I got syntax error in foreach. What is the correct way of using foreach inside array of Query Builder, code as follows:
public function postItems(Request $request, $id){
$itemid = \DB::table('items_tables')->where('category_id','=',$id)->get();
DB::table('store_items')->insert(
array('user_id' => \Auth::user()->id,
foreach($itemid as $itemids){
'items' => $itemids->name,
}
'store_id' => $id)
);
return view('actions.itemstore');
}
Syntax error occurred as follows in foreach:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')'
$itemids->name variable have numerous value. I need to loop through this.
insert()with wrongly structured array. You're using loop instead ofpluck(). DB architecture is bad. Wrong syntax everywhere. You should really read Laravel and PHP docs. This will save you a lot of time.