Computer Science, asked by kliptu, 11 months ago

How to pass data array from Controller to blade View in Laravel ?

Please write example!

Answers

Answered by umaraligourgmailcom
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 dharm1992m
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