In my Laravel 5.6 application, I try to pass a $id
variable from my route to each single column of my datatable.
My code:
public function getVendorslistChange($id){
try {
return Datatables::of($this->purchaseRepository->getVendorListData(),$id)
->addColumn('action', function ($vendor,$id) {
return \Form::open(['method' => 'POST', 'action' => ['PurchaseController@postChangeVendor',$id], 'class' => 'form']) . '
<input type="hidden" name="id" value="' . $vendor->id . '" />
<input type="submit" name="submit" value="Choose" class="btn center-block" />
' . \Form::close();
})
->make(true);
} catch (\Exception $e) {
return $this->redirectWithErrors($e);
}
}
this part $this->purchaseRepository->getVendorListData()
will return the following:
public function getVendorListData(){
$this->vendors = Vendor::Select(
array(
'vendors.id',
'vendors.company_name'
))
->where('vendors.company_id',return_company_id())
->where('status','Active')->get()
;
return $this->vendors;
}
But there is error said, the $id
cannot be passed to the addColumn
.
Too few arguments to function App\Http\Controllers\PurchaseController::App\Http\Controllers{closure}(), 1 passed in /Applications/XAMPP/xamppfiles/htdocs/laravel-project/american_dunnage/vendor/yajra/laravel-datatables-oracle/src/Utilities/Helper.php on line 64 and exactly 2 expected
What is the proper way to pass parameter like this to each column of the datatable?