Monday, March 19, 2018

Always remember users in Laravel - development

Always remember users in Laravel

How could I make it so that in my laravel sign in controller, users are always remembered?

I tried making $remember_me = 1

but that doesn’t seem to work.

Controller:

public function postSignin(Request $request, AppMailer $mailer) {
    $this->validate($request, [
        'email' => 'required',
        'password' => 'required',
    ]);     

    $username = $request->get('email');
    $password = $request->get('password');

    $field = filter_var($username,FILTER_VALIDATE_EMAIL)? 'email': 'username';      

    Auth::attempt([$field => $username, 'password' => $password], true);


    return redirect()->back()->with('info', 'You are now signed in.');
}       

Start of Home controller:

public function getIndex() {
    if (Auth::check()) {

        if (Auth::viaRemember()) {
            dd('test');
        }

Edit: I changed the code a bit to explain why the current answer isn’t working for me.



from Laravel Questions and Answers https://laravelquestions.com/laravel/always-remember-users-in-laravel/
via Lzo Media

No comments:

Post a Comment