yervandbag liked this thread
The best way to do this is make use of Middleware. Jeffrey Way made a great lesson about middleware in his Laravel 5 Fundamentals series here: https://laracasts.com/series/laravel-5-fundamentals/episodes/16
That way you don't have to copy & paste the same snippet of code for every controller method.
yervandbag liked this reply
As above, but to get rid of the \
you just need to add a use at the top of the Controller:
use Auth;
You'll then be able to use Auth::check()
in your code, without the \
.
I didnt get anything back with Auth::check(), maybe it works, I dont know why, but this works.
if($user = Auth::user())
{
// do what you need to do
}
IF you want to display something when not logged in, do this:
if(Auth::guest())
{
// do what you need to do
}
works in 5.2.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community