How to resolve $ user variable in blade view page in Laravel?
I have this support.blade.php page in the views folder and I am using Laravel.
I cannot highlight $user->id
or $user[id]
on this page and I am getting undefined variable. This can be repeated on other pages like ticket.blade.php, but it doesn't work on that particular page.
How can I fix this?
You need to pass data from the controller method first:
return view('support', ['user' => $user]);
If you want to display the ID of the authenticated user, you can do so from anywhere in the application without passing data from the controller method:
{{ auth()->user()->id }}
Inside the service provider, you can use
View::share('key', 'value')
You can refer to the docs for a more detailed explanation.
Have you passed data to a view file?
return view('support', ['user' => $user]);