0

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 1

2

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 }}
Sign up to request clarification or add additional context in comments.

2 Comments

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 }}) }}
@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 {{ ... }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.