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

Tob*_*ude 1 php laravel

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

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.');

    }
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我不断收到此错误 Call to undefined function App\Http\Controllers\Auth\array_get() 有人可以教我如何解决此错误吗?

非常感谢提前。

Ank*_*hra 8

在 Laravel 6 中使用\Arr::get()代替array_get()。 array_get() 在 Laravel 6.x 中已弃用。所以检查这个:

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.');

}
Run Code Online (Sandbox Code Playgroud)