Laravel did not remember the login

I am using manual authentication in Larave, here is my code function

public function doLogin(){
  // create our user data for the authentication
  $userdata = array(
    'username' => Input::get('username'),
    'password' => Input::get('password')
  );

  // attempt to do the login
  if (Auth::attempt($userdata,true)) {
    return (Auth::check() ? 'true' : 'false');
  }
  else {
    // validation not successful, send back to form
    return (Auth::check() ? 'true' : 'false');
  }
}

After logging in Auth::check, true is returned. But after viewing protected routes that have this build function

public function __construct()
{
  $this->middleware('auth');
}

middleware redirects me to the login page again, even after logging in.

Authmiddleware never changed. Are there any changes I need to make?

I also tried my own middleware:

class LoginCheck
{
    public function handle($request, Closure $next)
    {
      if (!Auth::check()) {
          if ($request->ajax() || $request->wantsJson()) {
              return response('Unauthorized.', 401);
          } else {
              return redirect('login');
          }
      }
        return $next($request);
    }
}

Still not working, means that Auth :: check () returns false.

Cookies are configured to save the session and still do not work.

+4
source share
1 answer

, ...

Laravel. MVC ( ), auth. php artisan make:auth, , , .

, , , - , .

, !

0

All Articles