jeudi 28 juillet 2016

Foreach in controller in laravel 5.2

I want to $selected_student in foreach in selecct query should select all column with all respected student_id and then display datatable (It is not doing same and giving errors).

I am 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 as $select_student)
    {

            $student[] = student::select('student_id', 'first_name','middle_name','last_name', \DB::raw('CONCAT(first_name, " ",middle_name, " " ,last_name) AS 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) AS 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) AS 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) AS address'));
    return Datatables::of($student)
    ->make(true);
  }


}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ayjQS8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire