Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !

like image 713
LarakBell Avatar asked Feb 12 '20 12:02

LarakBell


2 Answers

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

composer update

This works for me

like image 65
Ahmed Hegazy Avatar answered Oct 21 '22 19:10

Ahmed Hegazy


I have faced the same problem when I use laravel version 5.8.* and php version 7.4. I have solved this issue update composer. I just use this command in terminal

composer update

or

php composer.phar update

and fixed my issue easily.

like image 8
A.A Noman Avatar answered Oct 21 '22 19:10

A.A Noman