Passing data from controller to view in Laravel

前端 未结 9 1777
我在风中等你
我在风中等你 2020-11-30 10:26

I am new to laravel and I have been trying to store all records of table \'student\' to a variable and then pass that variable to a view so that I can display them.

9条回答
  •  囚心锁ツ
    2020-11-30 10:44

    Can you give this a try,

    return View::make("user/regprofile", compact('students')); OR
    return View::make("user/regprofile")->with(array('students'=>$students));
    

    While, you can set multiple variables something like this,

    $instructors="";
    $instituitions="";
    
    $compactData=array('students', 'instructors', 'instituitions');
    $data=array('students'=>$students, 'instructors'=>$instructors, 'instituitions'=>$instituitions);
    
    return View::make("user/regprofile", compact($compactData));
    return View::make("user/regprofile")->with($data);
    

提交回复
热议问题