how to download pdf for a line from a table in laravel

Viewed 515

i want to generate pdf from the database for 1 row in a table , the table name is "listings"

i used that script for the controller :

class CreatePdfController extends Controller
 {
public function pdfForm(Request $request,$id){
    $listing = Listing::findOrFail($id);
    view()->share('listing',$listing);       
          if($request->has('download')){
            $pdf = PDF::loadView('pdf_download');
            return $pdf->download('pdf_download.pdf');
      }
    
    return view('show_details')->with('listing', $listing);
}
}

and for the show_details its the view where can i fetch just the data for 1 line in the table :

<div class="col-sm-8 offset-sm-2">

                       <a href="{{ route('show_details', ['id' => $listing->id ,'download'=>'pdf']) }}" class="btn btn-primary">Download PDF</a>




                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header col-xs-6">
                                        <div class="col-xs-3">
                                            <h2>Listing Ref n° :{{$listing->id}}</h2> 
                                             {{$listing->owner->owner_lastname}}</h4> 

                                        </div>
                                        <div class="col-xs-3">
                                            <img src="{{ asset('/assets/images/listings/'.$listing->listing_Fimage) }}" width="120px" height="100px" alt="image" >

                                        </div>

                                    </div>

                                    <div class="card-body">

                                        <div class="col-xs-7 well">
                                            <table id="example1" class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th scope="row">listing_title:</th>
                                                        <td>{{$listing->listing_title}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_type:</th>
                                                        <td>{{$listing->listing_type}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_purpose:</th>
                                                        <td>{{$listing->listing_purpose}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_location:</th>
                                                        <td>{{$listing->listing_location}}</td>
                                                    </tr>
                                                    <tr>

the pdf_download is the view that i want to generated as pdf :

 <table id="example1" class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th scope="row">listing_title:</th>
                                                        <td>{{$listing->listing_title}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_type:</th>
                                                        <td>{{$listing->listing_type}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_purpose:</th>
                                                        <td>{{$listing->listing_purpose}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_location:</th>
                                                        <td>{{$listing->listing_location}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_emirate:</th>
                                                        <td>{{$listing->listing_emirate}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_community:</th>
                                                        <td>{{$listing->listing_community}}</td>
                                                    </tr>
                                                    <tr>
                                                        <th scope="row">listing_price:</th>
                                                        <td>{{$listing->listing_price}}</td>
                                                    </tr>

                        </table>

and the route that i passed is :

 Route::get('/show_details/{id}' ,array('as'=>'show_details',
         'uses'=>'CreatePdfController@pdfForm'));

the problem is i get that error and i cannot download the pdf file :

**Symfony\Component\ErrorHandler\Error\FatalError

Maximum execution time of 60 seconds exceeded http://127.0.0.1:8000/show_details/3?download=pdf**

0 Answers
Related