无法显示来自外部网址的PDF

时间:2019-04-24 10:19:50

标签: laravel model-view-controller routes

我有一个外部api的URL:“ ** / loc / api.php / downloadfacture /”我必须添加2个参数$ numsoc和$ numfacture才能显示pdf文件。

我将Guzzle用作http客户端。

我只能从我的vue.blade访问var $ numsoc和$ numfactures(由于foreach $ data将另一个api解析为$ d)

问题:我可以在日志文件中看到该网址看起来不错 => 2019-04-24 09:49:19-获取downloadfacture / downloadfacture / 2795 numfact = 1218100031&numsoc = 12但我无法显示任何内容。

Laravel路由或错误的控制器方法,我看不到我的错误,需要您的帮助,以了解正确的方法。

谢谢!

这是控制器

public function downloadfactures($numsoc, $numfact)
    {
        $urid = config('params.base_uri.loc_download');
        $user = null;
        if (Auth::check()) {
            $user = Auth::user()->code_clt;
        }

        $client = new Client(['base_uri' => $urid]);
        $response = $client->request('GET', $user, [
            'query' => [
                'numsoc' => $numsoc,
                'numfact' => $numfact,
                'id' => '',
            ],
        ]);

        $data = $response->getBody()->getContents();
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename=report.pdf');
        echo $data;
    }

vue.blade.php

@if(isset($data ))
                    @foreach($data as $d)
                        <tr>
                            <td>{{$d->Contrat}}</td>
                            <td>{{$d->NomClient}}</td>
                            <td>{{$d->Conducteur}}</td>
                            <td>{{$d->Vehicule}}</td>
                            <td>{{$d->Annee}}</td>
                            <td>{{$d->Mois}}</td>
                            <td>{{$d->Dossier}}</td>
                            <td>{{$d->FactureNum}}</td>
                            <td>{{$d->Mht}}</td>
                            <td class="table-light"><a href=""><i class="fa fa-file-pdf-o" title="pdf"></i></a></td>
                            <td class="table-light"><a href="{{action('LocationController@downloadfactures', ['numsoc' => $d->Soc,'numfact' => trim($d->FactureNum)])}}" target="_blank"><i class="fa fa-files-o" title="duplicata"></i></a></td>
                            <td class="table-light"><a href=""><i class="fa fa-book" title="annexes" aria-hidden="true"></i></a></td>
                        </tr>
                    @endforeach
                @else
                @endif

web.php

Route::get('/download/{numsoc}/{numfact}', 'LocationController@downloadfactures')->name('download');

错误消息:

致命错误:在第552行的** \ api \ loc \ api.php中调用未定义的函数http_response_code()

0 个答案:

没有答案