Havihavi Havihavi -4 years ago 196
Ajax Question

Setting remember on ajax laravel login

Rebuilding my system using laravel 5.4.
I do an ajax login that works, but i want to add the remember option to the auth.
the documentation says this about setting remember:

if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
// The user is being remembered...

But since my logincontroller does not have any visible login function, i am struggling with how to override it with my current logincontroller.
in my route i am just calling LoginController@login. and i have no override on the login function being called..

This is my logincontroller:

namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;

use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;
class LoginController extends Controller

use AuthenticatesUsers;
protected $redirectTo = '/minside';
public function __construct()
$this->middleware('guest', ['except' => 'logout']);
protected function sendLoginResponse(Request $request)
if ($request->ajax()) {
return response()->json($this->guard()->user(), 200);
return $this->authenticated($request, $this->guard()->user())
?: redirect()->intended($this->redirectPath());
protected function sendFailedLoginResponse(Request $request)
if ($request->ajax()) {
return response()->json([
'error' => Lang::get('auth.failed')
], 401);
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
$this->username() => Lang::get('auth.failed'),

Answer Source

When using the LoginController class provided by Laravel, it does this check:

protected function attemptLogin(Request $request)
    return $this->guard()->attempt(
        $this->credentials($request), $request->has('remember')

Simply include 'remember' to your request, to remember the user login.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download