Toby Nwude
Toby Nwude

Reputation: 411

Call to undefined function App\Http\Controllers\Auth\array_get() in laravel 6.16

in my controller I create a function to validate user and notify via mail

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

    }

For some reason, I keep getting this error Call to undefined function App\Http\Controllers\Auth\array_get() Can someone please teach me how to fix this error ?

Much appreciated in advance.

Upvotes: 2

Views: 8278

Answers (1)

Ankur Mishra
Ankur Mishra

Reputation: 1296

Use \Arr::get() instead of array_get() in laravel 6. array_get() deprecated in Laravel 6.x. So check this:

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

}

Upvotes: 9

Related Questions