2

I have make a html view page for generate to a pdf report from this view and i have also installed dompdf library, i have loaded data from database table on this view and create a hyperlink name as Download pdf. but when i click on this link it's show undefined variable dsale error.

here my controller method.

 //pass data to view public function dsreport($id,$fromdate,$todate) { $dsale=DB::table('directsales') ->join('clients','directsales.client_id','=','clients.id') ->join('products','directsales.product_id','=','products.id') ->select('clients.client_name','clients.addr','directsales.*','products.name') ->where('directsales.client_id','=',$id) ->whereBetween('directsales.issue_date',[$fromdate,$todate]) ->distinct() ->paginate(3); //->get(); $sumt=DB::table('directsales') ->where('directsales.client_id','=',$id) ->sum('directsales.total'); return view('reports.directsalereport',compact(['dsale','sumt'])); } //generate pdf public function dsalepdf() { $pdf=PDF::loadView('reports.directsalereport'); return $pdf->download('dsread.pdf'); } 

Here is my view part.

<div class="panel-body"> <center><h1><strong>M/s. Priti Enterprise</strong></h1></center> </center> <center><h2><i>Daily Sales Report</i></h2></center> <div class="row"> <div class="col-md-4"><strong>Client Name: {{$dsale[0]->client_name}}</strong></div> <div class="col-md-4"></div> <div class="col-md-4"><strong>Delivered by: {{$dsale[0]->deliverd_by}}</strong></div> </div><br> <div class="row"> <div class="col-md-4"><strong>Client address: {{$dsale[0]->addr}}</strong></div> <div class="col-md-4"></div> <div class="col-md-4"><strong>Date: {{$dsale[0]->issue_date}}</strong></div> </div><br><br> <table class="table table-bordered"> <thead> <th class="col-md-1">SL no.</th> <th>Product Name</th> <th>Invoice no.</th> <th>Unit per ctn.</th> <th>Unit price</th> <th class="col-md-2">Sales</th> <th>Value</th> </thead> <tbody> @foreach($dsale as $d) <tr> <td>#</td> <td>{{$d->name}}</td> <td>{{$d->transaction_code}}</td> <td>{{$d->unitperctn}}</td> <td>{{$d->unitprice}}</td> <td>{{$d->ctn}} ctn {{$d->pcs}} pcs</td> <td>{{$d->total}}</td> </tr> @endforeach </tbody> </table> <div class="col-md-11"></div> <div class="row"><strong>Total:{{$sumt}}</strong></div> <div>{{$dsale->links()}}</div> <div class="col-md-8"></div> <div class="row"> <a href="{{route('downpdf')}}" class=" btn btn-info"><i class=" glyphicon glyphicon-ok"></i> Download PDF</a> </div> </div> 
3
  • what is the exact error message? Commented Dec 4, 2017 at 7:50
  • and post this view code reports.directsalereport Commented Dec 4, 2017 at 7:51
  • @Gabrielle is your problem solved? :) Commented Dec 7, 2017 at 7:36

2 Answers 2

3

You have an array in compact.

You should use <div>{{$dsale[0]->links()}}</div>.

I think you should dont compact an array.

return view('reports.directsalereport',compact('dsale','sumt')); 

Edited: You should pass data to your Pdf view, too, so your method for downloading pdf should look like this.

public function dsalepdf() { $dsale=DB::table('directsales') ->join('clients','directsales.client_id','=','clients.id') ->join('products','directsales.product_id','=','products.id') ->select('clients.client_name','clients.addr','directsales.*','products.name') ->where('directsales.client_id','=',$id) ->whereBetween('directsales.issue_date',[$fromdate,$todate]) ->distinct() ->paginate(3); $sumt=DB::table('directsales') ->where('directsales.client_id','=',$id) ->sum('directsales.total'); $pdf=PDF::loadView('reports.directsalereport',['dsale' => $dsale,'sumt'=> $sumt]); return $pdf->download('dsread.pdf'); } 
Sign up to request clarification or add additional context in comments.

3 Comments

i'm try this things, but still now show the error Undefined variable: dsale
@Gabrielle please dd($dsale,$sumt) before return.
@Gabrielle dont forget to pass your data into pdf view
0

You may need to delete the vendor folder, then run composer install

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.