I am new to laravel, Please bear with me How would I pass the current logged on user from the controller to the view?
1 Answer
You don't need to pass it to the view.
Using the Auth facade, or auth() helper you have access to the current user:
// Use the Auth facade
{{ Auth::user()->email }}
// Or use the Auth helper:
{{ auth()->user()->email }}
2 Comments
Fluxify
Uhmm, one more thing. how would I do it in a form hidden like this, there seems to be an error {{ Form::hidden('user_id', {{ auth()->user()->id }}) }}
Elias Soares
@RHAMAB The problem is the same of this question: stackoverflow.com/questions/39283247/laravel-nested-blade-echos/… You are trying to put blade tags inside blade tags. Once you opened blade tags, you are writing PHP, not blade anymore. So you should do:
{{ Form::hidden('user_id', auth()->user()->id) }} Note the use of just a pair of {{ ... }}