Support the ongoing development of Laravel.io →
Authentication
Last updated 2 years ago.
0

You should check for loggedin users in a filter and then specify that in your routes where applicable. Laravel comes with a filter for that right from the start. No need to check for it in controllers and def not within views.

Last updated 2 years ago.
0

I am checking it in view all the time to decide, what parts of page will be visible or not! :)

Last updated 2 years ago.
0

For really simple apps this might work, but most apps will need some kind of role/permission based system, so you check if someone is logged in during a request and then later decide what to show, based on either permissions, roles or both.

Last updated 2 years ago.
0

shabushabu i hear ya but like TorchSK said i have many views were only login user can see certain sections etc that is why i am calling Auth::check all the time

what do people think? calling Auth::check directly everywhere or set it into a variable and pass it into view

hy

Last updated 2 years ago.
0

i think ideally i like to set some variable at some global level where every request i can access this variable, because really you should only need to call this ONCE per request, this way within all views, controllers, methods, model i can use this variable, instead of call Auth::check everywhere

is this good idea?

Last updated 2 years ago.
0

If it's for partial view, then a view composer might be a good idea. Otherwise, a filter will be better.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.