Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adhik13th's avatar

export PDF get error ''Too few arguments to function App\Http\Controllers\AdminController::getPDF(), 0 passed and exactly 1 expected''

i create export pdf on MY TABLE data , so this table no need $id like i export profile user or anything , but in this table i have search date range in this table ,and this result will can export pdf by Dompdf .

this is my controller :

 public function journal_sarpras()
{
    $ipsrs_id = Auth::user()->roles->ipsrs_id;

    $journal    = Aduan::with('users')->where('ipsrs_id',$ipsrs_id)->orderBy('created_at', 'desc')->paginate(10);
    return view('sarpras.journal_sarpras',['journal' => $journal ]);
}
  1. public function search_range(Request $request) {

     $ipsrs_id = Auth::user()->roles->ipsrs_id;
     $from = $request->from;
     $to = $request->to;
     $status = $request->status;
    
     if($status == 'Belum Selesai'){
         $new_status =['Tindakan Lanjutan' , 'Belum Dikerjakan' ,'Sedang Dikerjakan'];
     }
     
     elseif($status == 'Semua Laporan'){
         $new_status = ['Tindakan Lanjutan' , 'Belum Dikerjakan', 'Sedang Dikerjakan' , 'Selesai'];
     }
     else{
         $new_status = 'Selesai';
     }
    
     $stats = collect($new_status);
    
     $journal = Aduan::where('ipsrs_id',$ipsrs_id)->whereIn('status',$stats)
     ->whereBetween('created_at', [$request->get('from'), $request->get('to')])->paginate();
    
     //dd($aduan);
    
     return view('sarpras.journal_sarpras',['journal' => $journal]);
     
    

    }

  1. public function getPDF($journal){

     $pdf = PDF::loadView('file_pdf', ['journal' => $journal]);
     dd($pdf);
     return $pdf->stream('file_pdf.pdf')->header('Content-Type','application/pdf');
    

    }

this 3 controller is View Table ,View Search Date range and export Pdf .on this export pdf i using variable on search pdf to parse this data in view like data viewed on table.

and this is my route

Route::get('getPDF', 'AdminController@getPDF')->name('getPDF');

and parsing on this view

<a href="{{route('getPDF')}}" class="btn btn-primary" target="_blank">CETAK PDF</a>

but this is having error

Too few arguments to function App\Http\Controllers\AdminController::getPDF(), 0 passed and exactly 1 expected

what wrong with this pdf ?

0 likes
4 replies
experimentor's avatar

getPDF method is expecting a $journal object. You are not passing it either in the blade file or the route. You can use Route Model binding for this.

in blade file:

<a href="/getPDF/{{$journal->id}}" class="btn btn-primary" target="_blank">CETAK PDF</a>

In route:

Route::get('getPDF/{journal}', 'AdminController@getPDF')->name('getPDF');

In controller:

public function getPDF(Aduan $journal)

Don't forget to "use" the model Aduan in controller.

Having said this, looks like there are quite a few gotchas in your code. I cannot understand the language. Can't help completely. Example: $journals is a paginate object. Need to figure out how to get the id of each in your blade file.

Hope this helps.

Cheers

adhik13th's avatar

<a href#="/getPDF/{{$journal->id}}" class="btn btn-primary" target="_blank">CETAK PDF

on this line , why u use $journal->id ? this is have error if i use this, because i no need id for all table data ,i remove this $id , i get 404 not found ,

but if i remove all $Journal this pdf can load normally WITHOUT data

adhik13th's avatar

its have error

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id

Please or to participate in this conversation.