Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel还记得我,用Auth::trunt运行吗?_Php_Laravel - Fatal编程技术网

Php Laravel还记得我,用Auth::trunt运行吗?

Php Laravel还记得我,用Auth::trunt运行吗?,php,laravel,Php,Laravel,所以我有这个代码: 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' //

所以我有这个代码:

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.');
        }
    }
}

当它运行时,我得到:
语法错误,意外','
。基本上,它并不期望$memory被传递到那里。它应该在哪里?我试着把它放在这里:
Auth::trunt($userdate),$memory){}
,但这也不起作用。它也有同样的错误。不知道发生了什么事。任何帮助都将不胜感激。

您可以在您的Authcontroller中使用
Auth::vialemory()
,检查用户是否已登录:

if (Auth::check() || Auth::viaRemember()) {...
并更改您的登录检查,如下所示:

//Assuming, the remember-input is a checkbox and its value is 'on'
if (Auth::attempt($userData, (Input::get('remember') == 'on') ? true : false)) {...