How to pass data array from Controller to blade View in Laravel ?
Please write example!
Answers
Answered by
0
Answer:
I have a controller - ProfileController and inside that a function:
public function showstudents()
{
$students = DB::table('student')->get();
return View::make("user/regprofile")->with('students',$students);
}
In my view I have this code
<html>
<head></head>
<body> Hi {{Auth::user()->fullname}}
@foreach ($students as $student)
{{$student->name}}
@endforeach
@stop
</body>
</html>
I am receiving this error : Undefined variable: students (View:regprofile.blade.php)
Answered by
0
Answer:
Explanation:
MyfileController.php
public function index()
{
$data = [];
$data['user_id'] = Auth::user()->id;
return view('myfile', $data);
}
myfile.blade.php
<p>{{$user_id}}</p>
Similar questions
Chemistry,
5 months ago
Math,
5 months ago
Social Sciences,
5 months ago
Biology,
11 months ago
Physics,
11 months ago