php - Foreach in controller in laravel 5.2 -
i want $selected_student in foreach in selecct query should select column respected student_id , display datatable (it not doing same , giving errors).
i using yajra datatable.
controller
public function anydata(request $request) { $selected_batch_value = session::get('batch_selection'); $select_student = db::table('student_batch') ->select('student_id') ->where('batch_id', '=', $selected_batch_value) ->get(); if($selected_batch_value != 0) { foreach($select_student $select_student) { $student[] = student::select('student_id', 'first_name','middle_name','last_name', \db::raw('concat(first_name, " ",middle_name, " " ,last_name) full_name'), 'mobile_num', 'email','address_line1','address_line2','state','city','pincode',\db::raw('concat(address_line1, "<br>",address_line2, "<br> " ,state, "<br>",city,"<br>",pincode) address')) ->where('student_id', '=', $select_student->id) ->get(); } return datatables::of($student)->make(true); } else { $student = student::select('student_id', 'first_name','middle_name','last_name', \db::raw('concat(first_name, " ",middle_name, " " ,last_name) full_name'), 'mobile_num', 'email','address_line1','address_line2','state','city','pincode',\db::raw('concat(address_line1, "<br>",address_line2, "<br> " ,state, "<br>",city,"<br>",pincode) address')); return datatables::of($student)->make(true); } }
the error in foreach
loop,
this structure or foreach
loop,
foreach ($variable $key => $value){ # code... }
in case $variable
, $value
same, both $select_student
. change to,
foreach($select_student $value){ $student[] = student::select('student_id', 'first_name','middle_name','last_name', \db::raw('concat(first_name, " ",middle_name, " " ,last_name) full_name'), 'mobile_num', 'email','address_line1','address_line2','state','city','pincode',\db::raw('concat(address_line1, "<br>",address_line2, "<br> " ,state, "<br>",city,"<br>",pincode) address')) ->where('student_id', '=', $value->id) ->get(); }
Comments
Post a Comment