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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -