gpt4 book ai didi

php - 在 Laravel 6.16 中调用未定义函数 App\Http\Controllers\Auth\array_get()

转载 作者:行者123 更新时间:2023-12-05 08:51:09 25 4
gpt4 key购买 nike

在我的 Controller 中我创建了一个函数来验证用户并通过邮件通知

protected function register(Request $request)
{
/** @var User $user */
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
try {
$validatedData['password'] = bcrypt(array_get($validatedData, 'password'));
$validatedData['activation_code'] = str_random(30).time();
$user = app(User::class)->create($validatedData);

} catch (\Exception $exception) {
logger()->error($exception);

return redirect()->back()->with('message', 'Unable to create new user.');
}
$user->notify(new UserRegisteredSuccessfully($user));

return redirect()->back()->with('message', 'Successfully created a new account. Please check your email and activate your account.');

}

出于某种原因,我不断收到此错误调用未定义函数 App\Http\Controllers\Auth\array_get()有人可以教我如何解决这个错误吗?

非常感谢。

最佳答案

在 Laravel 6 中使用 \Arr::get() 而不是 array_get()。Laravel 6.x 中弃用了 array_get()。所以检查一下:

protected function register(Request $request)
{
/** @var User $user */
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
try {
$validatedData['password'] = bcrypt(\Arr::get($validatedData, 'password'));
$validatedData['activation_code'] = \Str::random(30).time();
$user = app(User::class)->create($validatedData);

} catch (\Exception $exception) {
logger()->error($exception);

return redirect()->back()->with('message', 'Unable to create new user.');
}
$user->notify(new UserRegisteredSuccessfully($user));

return redirect()->back()->with('message', 'Successfully created a new account. Please check your email and activate your account.');

}

关于php - 在 Laravel 6.16 中调用未定义函数 App\Http\Controllers\Auth\array_get(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60381298/

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