Hi,
Could anyone shed some light on how to add a variable inside the editColumn Method.
$taxRate = $company_detail->tax_rate;
$datatables = Datatables::of($items)
->editColumn('rrp_price', function($item) {
// return $item->rrp_price;
return round($item->rrp_price / ( 1 + ($taxRate / 100.0) ), 2);
})
return $datatables->make(true);
It is always showing me undefined variable $taxRate.
You should use use
in your closure like below:
$taxRate = $company_detail->tax_rate;
$datatables = Datatables::of($items)
->editColumn('rrp_price', function($item) use($taxRate) {
// return $item->rrp_price;
return round($item->rrp_price / ( 1 + ($taxRate / 100.0) ), 2);
})
return $datatables->make(true);
Can i use multiple closure?
E.g ->editColumn('rrp_price', function($item) use($taxRate, $newVar) {
or should I just make it into an array?
Yes, you can pass multiple variables or in array. It depends on your preference but I suggest you pass each variable.
Okay, noted and thank you for your quick response. It's working now :+1:
Most helpful comment
You should use
use
in your closure like below: