Search code examples
phplaravellaravel-5

Error "Trying to access array offset on value of type null" laravel 5.8.26 Php 7.4.2


I use below function for insert/create new user from admin panel:

public function store(Request $request)
{
    $this->validate($request, [
        'name' => 'required',
        'email' => 'required|email|unique:users,email',
        'password' => 'required|same:confirm-password'
    ]);


    $input = $request->all();
    $input['password'] = Hash::make($input['password']);


    User::create($input);

    return redirect()->route('admin.pages.users.index')
        ->with('success','User created successfully');
}

when I submit I get error as below :-

Trying to access array offset on value of type null

EDIT: I found my problem. my problem is email validation rule. when i remove email validation insert data is true.

enter image description here

How do can i fix this error !


Solution

  • Change Your Php version in Composer.json to 7.4.1 and run

    composer update
    

    This works for me