如何更改Laravel中的身份验证模型

如何更改Laravel中的身份验证模型,laravel,laravel-5,Laravel,Laravel 5,我需要将Laravel应用程序中的默认用户模型更改为管理模型。我遵循了中给出的教程 管理员模型必须进行身份验证、注册和重置密码。这就是我到目前为止所做的 在做了phpartisanmake:auth之后,我创建了Admin.php模型 这是config/auth.php 这是RegisterController.php 此代码在admins表中创建用户,但当我尝试登录时,它抛出以下错误: 传递给Illumb\Auth\SessionGuard::\uuu construct()的参数2必须

我需要将Laravel应用程序中的默认用户模型更改为管理模型。我遵循了中给出的教程

管理员模型必须进行身份验证、注册和重置密码。这就是我到目前为止所做的

在做了
phpartisanmake:auth
之后,我创建了
Admin.php
模型

这是
config/auth.php

这是
RegisterController.php

此代码在
admins
表中创建用户,但当我尝试登录时,它抛出以下错误:

传递给Illumb\Auth\SessionGuard::\uuu construct()的参数2必须是Illumb\Contracts\Auth\UserProvider的实例,给定为空,在第125行的…\vendor\laravel\framework\src\Illumb\Auth\AuthManager.php中调用


我不明白为什么会发生这种错误

config/auth.php
上更改代码:

'web' => [
        'driver' => 'session',
        'provider' => 'admins',
 ],
致:


所有身份验证驱动程序都有一个用户提供程序

这定义了如何从数据库或此应用程序用于持久化用户数据的其他存储机制中检索用户

config/auth.php
文件中更改如下:

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ]
]

AuthServiceProvider..@Demonyowh Admin.php位于管理模块中。请说得具体点哇!它起作用了,管理员在
admins
表中,为什么这样做呢?因为您实际上没有名为admins的提供者,所以您在
config/auth.php
中的提供者仍然被称为用户请看这里:
'users'=>['driver'=>'eloquent','model'=>\Modules\Admin\entications\Admin::class,]
因此,您实际上需要做的就是更改模型,使其指向您的管理模型,您已经做到了!:D
namespace App\Http\Controllers\Auth;

use Modules\Admin\Entities\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:admins'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return Admin::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}
'web' => [
        'driver' => 'session',
        'provider' => 'admins',
 ],
'web' => [
        'driver' => 'session',
        'provider' => 'users',
 ],
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ]
]