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

yervandbag liked this thread

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.

yervandbag liked this reply

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 9 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 8 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.