gpt4 book ai didi

php - Laravel 5.4 - 创建用户

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:06 24 4
gpt4 key购买 nike

我正在将 Facebook 登录集成到我的网络应用程序中,但出现此错误:

ErrorException in SessionGuard.php line 407: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, string given, called in /Applications/XAMPP/xamppfiles/htdocs/shop/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 294 and defined

我看到问题出在我创建新用户时:

public function findOrCreateUser($user, $provider)
{
$authUser = User::where('provider_id', $user->id)->first();
// if user exist login
if ($authUser) {
return $authUser;
}

// if user don't exist - Create new user
$test = DB::table('users')->insert([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);

return 'Hello'; // just try if it work!
}

用户已正确创建,但出现上述错误。我看不到我的消息“你好”。如果我像这样替换创建方法:

return User::create([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);

效果很好。但是我不想在创建用户后停止;我想返回另一个 View 。

最佳答案

在 laravel 中有几种方法可以将新行插入到表中。

一种方法是

User::create([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);
return view('your_view');

但是你需要在你的模型中有这个(用于批量分配)

protected $fillable = ['name','email','provider','provider_id'];

接下来是插入新行的其他方法

$user_database = new User;
$user_database->name = $user->name;
$user_database->email = $user->email;
$user_database->provider = $provider;
$user_database->provider_id = $user->id;
$user_database->save();
return view('your_view');

希望对你有帮助。如需更多帮助,请查看 official documentation

关于php - Laravel 5.4 - 创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42176473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com