1
I’m using the features offered by Standard for authentication, but even logged in the Auth::guest() command returns true, as if you were a guest.
Follow the code of mine middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class Autorizacao
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(!$request->is('/') && !$request->is('home') && !$request->is('login') && !$request->is('logout') && !$request->is('register') && Auth::guest()){
if(Auth::guest())
echo 'true';
else
echo 'false';
//return redirect('/login');
}
return $next($request);
}
}
I didn’t use dd() because it closes the process to display the result, and may not be able to log in.
In this case I would like the login screen to be displayed if the user was not logged in, but could access the login/logout or home routes, but if logged in would have access to all screens.
what
dd(Auth::user());
returns?– Guilherme Nascimento
There’s redundancy in the code, it’s calling
Auth::guest()
twice– Wallace Maxters
@Guilhermenascimento returns null
– MarceloSnts
Even when logged in?
– Guilherme Nascimento
@Guillhermenascimento yes
– MarceloSnts