Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
使用Auth::login时,Laravel 4 arg1必须是UserInterface的实例_Laravel_Laravel 4_Eloquent - Fatal编程技术网

使用Auth::login时,Laravel 4 arg1必须是UserInterface的实例

使用Auth::login时,Laravel 4 arg1必须是UserInterface的实例,laravel,laravel-4,eloquent,Laravel,Laravel 4,Eloquent,我有一个基本的laravel 4应用程序,允许某人注册然后登录。我正在尝试这样做,当用户成功完成注册时,他们会自动登录。我收到一个错误异常“传递给Illumb\Auth\Guard::login()的参数1必须是Illumb\Auth\UserInterface的实例,用户给定的实例”。我理解这意味着传递给login方法的第一个参数是不正确的,但我不理解为什么当用户说要使用时它是不正确的 $user = User::find(1); Auth::login($user); 这是我的控制器 &

我有一个基本的laravel 4应用程序,允许某人注册然后登录。我正在尝试这样做,当用户成功完成注册时,他们会自动登录。我收到一个错误异常“传递给Illumb\Auth\Guard::login()的参数1必须是Illumb\Auth\UserInterface的实例,用户给定的实例”。我理解这意味着传递给login方法的第一个参数是不正确的,但我不理解为什么当用户说要使用时它是不正确的

$user = User::find(1);

Auth::login($user);
这是我的控制器

<?php

    Class UsersController extends BaseController {

        public $restful = 'true';
        protected $layout = 'layouts.default';

        public function post_create()
        {
            $validation = User::validate(Input::all());

            if ($validation->passes()) {
                User::create(array(
                    'username'=>Input::get('username'),
                    'password'=>Hash::make(Input::get('password'))
                    ));

                $user = User::where('username', '=', Input::get('username'))->first();

                Auth::login($user);

                return Redirect::Route('home')->with('message', 'Thanks for registering!  You are now logged in!');
            }

            else {
                return Redirect::Route('register')->withErrors($validation)->withInput();
            }
        }

    }
?>

我可以想到几个场景:

  • 您没有使用全新的Laravel安装附带的
    用户
    模型(听起来不太可能,但该模型实现了
    用户界面
    ,如果您编辑或创建了新的用户界面,则您的用户可能没有)
  • User::create()
    未成功调用(未成功创建用户)
  • $user=user::where()->…
    不会产生结果
  • 尝试:


    如果仍然出现错误,则很可能
    $user
    不是
    用户
    对象,因为用户未成功创建。

    我可以想到以下几种情况:

  • 您没有使用全新的Laravel安装附带的
    用户
    模型(听起来不太可能,但该模型实现了
    用户界面
    ,如果您编辑或创建了新的用户界面,则您的用户可能没有)
  • User::create()
    未成功调用(未成功创建用户)
  • $user=user::where()->…
    不会产生结果
  • 尝试:


    如果仍然出现错误,则可能是由于用户未成功创建,
    $user
    不是
    用户
    对象。

    确保user.php的开头类似

    use Illuminate\Auth\UserInterface;
    use Illuminate\Auth\Reminders\RemindableInterface;
    
    class User extends Eloquent implements UserInterface, RemindableInterface {
    

    确保User.php的开头像

    use Illuminate\Auth\UserInterface;
    use Illuminate\Auth\Reminders\RemindableInterface;
    
    class User extends Eloquent implements UserInterface, RemindableInterface {
    

    选项一,我愚蠢地没有阅读安全文档的第一段,我直接跳到了身份验证部分。我只是让用户模型看起来与教程中的完全相同,令人惊讶的是,这不是一个好主意。我愚蠢地没有阅读安全文档的第一段,我只是直接跳到了验证部分。我只是让用户模型看起来和教程中的完全一样,这不是一个好主意