简体   繁体   English

在laravel 5.8注册期间添加ROLE时,参数1传递给Illuminate \\ Auth \\ SessionGuard :: login()

[英]Argument 1 passed to Illuminate\Auth\SessionGuard::login() when adding ROLE during registration in laravel 5.8

I am trying to add default ROLE upon registration of the user. 我正在尝试在用户注册时添加默认角色。 I add ->assignRole() but it gives me this error 我添加->assignRole()但它给了我这个错误

在此处输入图片说明

here's my create function 这是我的创建功能

use App\HasRoles;

protected function create(array $data)
{
    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    ])->assignRole('borrower');

    $user_id = $user->id;

    // HasRoles::create([
    //     'role_id' => 4,
    //     'user_id' => $users->id,
    // ]);

    Referral::find($data['referral_id'])->update ([
        'status'    => 1,
        'date_used' => $data['referral_date_used']
    ]);

    CollectorMember::create ([
        'collector_id' => $data['referral_generate_by'],
        'borrower_id'  => $user_id,
        'referral_id'  => $data['referral_id'],
    ]);
    return $user;
}

you'll also notice the commented hasRole::create. 您还会注意到注释的hasRole :: create。 well I thought that's just like that. 好吧,我以为就是这样。

Any suggestions? 有什么建议么? thanks in advance! 提前致谢!

Just add the assignRole() method after create the user. 创建用户后,只需添加assignRole()方法即可。

$user = User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'password' => Hash::make($data['password']),
]);
$user->assignRole('borrower');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注册错误,参数1传递给laravel 5.8中的Illuminate \\ Auth \\ SessionGuard :: login() - Registration error, Argument 1 passed to Illuminate\Auth\SessionGuard::login() in laravel 5.8 LARAVEL 7.0 传递给 Illuminate\\Auth\\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\\Contracts\\Auth\\Authenticatable,给定数组 - LARAVEL 7.0 Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, array given 社交名流:传递给 Illuminate\Auth\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable,给定 null - Socialite : Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given Laravel 8:传递给 Illuminate\Auth\SessionGuard::__construct() 的参数 2 必须是 Illuminate\Contracts\Auth\UserProvider 的实例,null 给定 - Laravel 8 : Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given 传递给SessionGuard :: login()的参数1必须是Laravel 5.2中Auth \\ Authenticatable的实例 - Argument 1 passed to SessionGuard::login() must be an instance of Auth\Authenticatable in Laravel 5.2 类型错误:参数1传递给Illuminate \\ Auth \\ SessionGuard :: login()寄存器上的重定向不起作用 - Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() redirection on register does not work Illuminate\Auth\SessionGuard::login(): 参数 #1 ($user) 必须是类型 - Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Laravel 5.8多次授权注册和登录 - Laravel 5.8 multiple auth registration and login TypeError: Illuminate\Auth\SessionGuard::login(): 参数 #1 ($user) 必须是类型 Illuminate\Contracts\Auth\Authenticatable,, App\Models\Admin giv - TypeError: Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable,, App\Models\Admin giv Laravel Messenger-传递给Illuminate \\ Auth \\ Guard :: login()的参数1必须实现Illuminate \\ Contracts \\ Auth \\ Authenticatable接口,给定null - Laravel messenger - Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM