So I have this code:
public function postLogin() {
// validate the info, create rules for the inputs
$rules = array(
'username' => 'required', // make sure the email is an actual email
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::route('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
$remember = (Input::has('remember')) ? true : false;
// create our user data for the authentication
$userdata = (array(
'username' => Input::get('username'),
'password' => Input::get('password')
), $remember);
// attempt to do the login
if (Auth::attempt($userdata)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
echo 'SUCCESS!';
} else {
// validation not successful, send back to form
return Redirect::route('login')
->with('global', 'Incorrect username or password. Please try again.');
}
}
}
When it runs I get: syntax error, unexpected ','
. Basically it isn't expecting the $remember to be passed there. Where is it meant to be? I've tried putting it here: Auth::attempt($userdate), $remember) { }
but that didn't work either. It had the same error. Not sure what's going on. Any help would be appreciated.