Data pass from controller to view in laravel

Data pass from controller to view in laravel

A. First Way

$instructors="";
$instituitions="";

$compactData=array('students', 'instructors', 'instituitions');
$data=array('students'=>$students, 'instructors'=>$instructors, 'instituitions'=>$instituitions);

return View::make("user/regprofile", compact($compactData, $newData));
return view("user/regprofile",compact('students','teachers','others'));
return View::make("user/regprofile")->with($data);
return View::make("user/regprofile", ['data' => $data]);


B. Second Way
public function showstudents() {
     $students = DB::table('student')->get();
     return (View::make("user/regprofile", compact('student')));
}

Leave a Reply