Support the ongoing development of Laravel.io →
Authentication Security Configuration
Last updated 1 month ago.
1

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.

1

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 \.

Last updated 6 years ago.
0

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.

Last updated 5 years ago.
0

Sign in to participate in this thread!

Cloudways

Your banner here too?

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.