Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Laravel 4 Authentication: Remember me is not working

both login and logout is working except remember me is not working. When it log out and it was the check box is empty and no remember. I tried withInput(); of code somewhere maybe I am missing that part or true : false; I dont know which one. please take a look at the code.

        public function postLogin()
    {
        $input = Input::all();

        $rules = array(
            'email' =>'required', 
            'password'=>'required');

        $v = Validator::make($input,$rules);



        if($v->fails())
        {

            return Redirect::to('login')
                ->withErrors($v);


        } else {

            $remember = (Input::has('remember')) ? true : false;  

            $auth = Auth::attempt(array(
                'email'=> Input::get('email'), 
                'password'=>Input::get('password')
                 ), $remember );

            if($auth)
            {

                return Redirect::intended('admin');

            } else {

                return Redirect::to('login')
                    ->withInput()
                    ->with('errorMessage2', 'Email/password wrong, or account not activated.');
            }
        }
    }

login.blade.php

                <div class="field">                         
                    <input name="remember" type="checkbox" id="remember"> 
                             <label for = "remember">Remember Me
                                     </label>
                           </div>

any idea? if you need more info please let me know

Hi Brian,

What laravel version are you using?

2 Answers

I looked at composer.json its a laravel/framework : 4.2

Markus Schober
Markus Schober
3,149 Points

Hi Brian,

take a look at the laravel docs. Here are some great examples.

if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
    // The user is being remembered...
}

The second parameter of the attempt method is for the remember_me function.

Don't forget, the users table must include the string remember_token column, which will be used to store the "remember me" token.