I want to pass data from my controller to blade view. What am I missing?
Controller:
public function getRolesFront(){
$roles= Role::join(
'user_roles',
'roles.id',
'=',
'user_roles.role_id')
->join(
'users',
'user_roles.user_id',
'=',
'users.id')
->select(
'user_roles.id AS row_id',
'user_roles.user_id',
'roles.name AS name',
'roles.function AS function',
'users.name AS user_name',
'user_roles.role_id')
->orderBy('user_roles.user_id')
->get();
return view('users_view', compact($roles));
}
web.php
Route::get('/userslist','RoleController@getRolesFront');
blade
<tr>
@foreach($roles as $role)
{{$role->role_id}}
@endforeach
</tr>
the error is:
Undefined variable: roles (View: C:\laragon\www\ProjectoFinalesources\views\users_view.blade.php)