lundi 13 janvier 2020

How to download pdf generated in laravel, from vuejs?

I have the following function in laravel for the generation of a pdf

public function download_agreement(Request $request){
        try{
           /*  $items = DB::table("items")->get();
                    view()->share('items',$items); */
            if($request->has('download')){
                $pdf = PDF::loadView('pdf.agency.agreement');
                return $pdf->download('pdfview.pdf');
            }
            return view('pdfview');
        }
        catch(\Exception $error){
            Log::error('[RegistrantsController] error in send_agreement ' . $error);
            return response()->json(['code' => 403, 'message' => 'Something went wrong']);
        }
    }

And then I'm doing the following:

downloadAgreement() {
      console.log("DOWNLOAD");
      let sendData = {
        uuid: this.$route.params.uuid,
        email: "email@gmail.com",
        download: true
      };
      axios({
        url: config.routePrefix + "/agency/download_agreement",
        method: "GET",
        data: sendData,
        responseType: "blob"
      }).then(response => {
        const url = response;
      });
}

But I get Internal Server error



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire