ErrorException Undefined variable: limit
not working limit and id ,, i want to insert is manually
public function import(Request $request)
{
$id= $request->id;
$limit = $request->limit;
$path = $request->file('file')->store('uploads');
$products = (new FastExcel)->import('public/' . $path, function ($line) {
return Data::create([
'uname' => $line['name'],
'username' => $line['username'],
'limit' => $limit,
'group_id' =>$id
]);
});
flash(__('Your products imported successfully'))->success();
return redirect()->route('products.index');
}
When you want to use them in a callback function you have to pass them using use in PHP:
$id= $request->id;
$limit = $request->limit;
$path = $request->file('file')->store('uploads');
$products = (new FastExcel)->import('public/' . $path, function ($line) use ($id, $limit) {
return Data::create([
'uname' => $line['name'],
'username' => $line['username'],
'limit' => $limit,
'group_id' =>$id
]);
});
Thanks its working now . :)
@shuvoo happy to hear that :) Please mark the answer as "Best Answer" then :)
Please or to participate in this conversation.