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.
I am checking it in view all the time to decide, what parts of page will be visible or not! :)
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.
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
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?
If it's for partial view, then a view composer might be a good idea. Otherwise, a filter will be better.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community