so what i am working on is when i check the remember me checkbox the user when logout the form (username and password) remember the user data like that :
so this is my code it not works :(
// create our user data for the authentication
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
// attempt to do the login
if (Auth::attempt($userdata, true)) {
Session::flash('message', array('body'=>trans('login-signup.welcome'), 'type'=>'success'));
return Redirect::to('/');
}
Use Cookies
cookie, is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website. Every time the user loads the website, the browser sends the cookie back to the server to notify the website of the user's previous activity
To create:
$response->withCookie(Cookie::make('name', 'value', $minutes));
To retrieve
$value = Cookie::get('name');
Your question is not to remember the user login.. The question is how to fill the inputs based on saved auth information. You can do that if you print the authentication values in the input value attribute while loading the page.
larval Cookies Docs
Also Laravel has it's own implementation of "Remember Me"
if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
// The user is being remembered...
}
if (Auth::viaRemember())
{
//
}
More information about "Authenticating A User And "Remembering" Them"
public function validate()
{
// set the remember me cookie if the user check the box
$remember = (Input::has('remember')) ? true : false;
// attempt to do the login
$auth = Auth::attempt(
[
'username' => strtolower(Input::get('username')),
'password' => Input::get('password')
], $remember
);
if ($ auth) {
return Redirect::to('home');
} else {
// validation not successful, send back to form
return Redirect::to('/')
->with Input(Input::except('password'))
->with('flash_notice', 'Your username/password combination was incorrect.');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With