I try to show variable from the controller to blade in laravel but the result is “Undefined Variable”
UserController.php
public function user(){ $people = ['Edwin','James','Rock','Peter','Maria']; return view('user', compact('people')); }
Web.php
Route::get('/user', function (){ return view('user');
});
user.blade.php
@if(count(array($people))) <ul> @foreach($people as $person) <li>{{$person}}</li> @endforeach </ul> @endif
I really appreciate your answer.
Advertisement
Answer
change your web.php file
use AppHttpControllersUserController; Route::get('/user', [UserController::class, 'user']);