2 months ago

opinion and feedback about calling a $user...

Posted 2 months ago by santino

Hi, laracast community I have been thinking about what's the best way to call a User in laravel projects, I think that there is no app if there is no USER , because you have the landing page where all are GUEST, But when we are really into the THING there must be a user, so my thoughts are that in all VIEWS and CONTROLLERS must be the instance of the USER , so in the app service provider I create this:

    public function boot()
        View::composer( [ 'pages.*' ] , UserComposer::class );

//// on UserComposer class got thiss

$view->with( 'user', Auth::user() );

So... now I can access all the pages to the instance $user, I want to have this instance in my controllers to... but I don't know how to do it, now I ask my self... This is the right way to do it? , I mean should I call this instance in the controllers too, and can be called in the MODELS?

I end up with this because I see that I have to call this Auth::user() in all the controller's methods and then in the view blade the same thing, so I want to know how do you manage this? whats the best way to affront this.

Very grateful to count with this excellent laracast forum community Thanks in advance for your feedback

Regards Santino

Please sign in or create an account to participate in this conversation.