如何使用VueJS并应用DOMPDF解决Laravel函数中“函数的参数太少”的问题?

时间:2018-12-29 17:10:24

标签: laravel vue.js dompdf

我正在使用Laravel和VueJS制作一个实验室应用程序,在其中我要制作报告的PDF文档。为此,我安装了DOMPDF。 当我尝试在VueJS中执行该方法以打开PDF时,出现以下错误: "Too few arguments to function App \ Http \ Controllers \ SampleController :: reportShow (), 1 passed and exactly 2 expected" 我究竟做错了什么? 从已经非常感谢您

MuestraController:

public function informeMuestra(Request $request,$id){
    $id = $request->id;
    $muestra = Muestra::join('remitentes', 'remitentes.id', '=', 'muestras.remitente_id')
                ->join('solicitantes', 'solicitantes.id', '=', 'muestras.solicitante_id')
                ->join('localidads', 'localidads.id', '=', 'muestras.localidad_id')
                ->select('muestras.*', 'remitentes.nombre as nombre_remitente', 'solicitantes.nombre as nombre_solicitante', 'solicitantes.direccion as direccion_sol', 'localidads.localidad')
                ->where('muestras.id', '=', $id)->take(1)->get();
    $pedidos = EnsayoMuestra::join('ensayos', 'ensayo_muestra.ensayo_id', '=', 'ensayos.id')
                ->join('muestras', 'ensayo_muestra.muestra_id', '=', 'muestras.id')
                ->select('ensayo_muestra.*', 'ensayos.ensayo as ensayo', 'ensayos.metodo as metodo', 'ensayos.unidades as unidades')
                ->where('ensayo_muestra.muestra_id', '=',$id)
                ->orderBy('ensayo_muestra.id', 'asc')->get();

    $num_muestra=Muestra::select('numero')->where('id',$id)->get();

    $informe = \PDF::loadView('pdf.informemuestra',['muestra'=>$muestra,'pedidos'=>$pedidos]);
    return $informe->stream('muestra-'.$num_muestra[0]->numero.'.pdf');

Muestra.vue:

cargarInforme(id){
            window.open('http://localhost/dsa/public/muestra/informeMuestra?id' + id + ',' + '_blank');
        },

Route (web.php):

Route::get('/muestra/informeMuestra/{id}', 'MuestraController@informeMuestra')->name('muestra_pdf');

1 个答案:

答案 0 :(得分:0)

最后,唯一适用于我的解决方案是:

window.open('http://localhost/dsa/public/muestra/informeMuestra/'+ id);