18

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 !

LarakBell
  • 596
  • 1
  • 7
  • 19

6 Answers6

29

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

composer update

This works for me

Ahmed Hegazy
  • 306
  • 3
  • 3
  • 1
    If your site is live and can't update the composer, you may toggle the PHP version in your web host cpanel between PHP 7.3 and 7.4 Your answer just saved me hours of work.. thanks – icynets Jul 03 '21 at 16:53
  • 1
    place isset function in vendor/illuminate/support/ServiceProvider.php on line 84 isset($this->app->config['view']) && isset($this->app->config['view']['paths']) – Hayk Abrahamyan Aug 02 '22 at 19:21
9

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.

A.A Noman
  • 5,244
  • 9
  • 24
  • 46
  • Even if that command is very dangerous to commit. It also solved my problem. I was having problems with unit testing using Laravel 5.8 and PHP 7.4. – Mycodingproject Jan 01 '21 at 17:16
  • @Mycodingproject, It is my pleasure to solve your problem – A.A Noman Jan 01 '21 at 17:32
  • This worked for me. I have updated one of the module and this problem came, but after I run composer update, it solved. Thank you! – Billa Dec 15 '22 at 18:18
7

In line 147 of this file vendor\egulias\email-validator\EmailValidator\Parser\Parser.php

Change it from this if ($previous['type'] === EmailLexer::S_BACKSLASH

To this if (isset($previous['type']) && $previous['type'] === EmailLexer::S_BACKSLASH ...

Liga
  • 3,291
  • 5
  • 34
  • 59
  • 8
    A vendor package should never be modified directly, subsequent updates via composer update may overwrite any changes you make. – Danzapps Jul 12 '21 at 02:25
  • @Danzapps sometimes when doing something on a dev server without all access rights you want to temporarily hotfix vendor packages so you won't break the production by `composer update` – user151496 Jul 11 '22 at 12:08
3

I had the same problem for a production app and changing the PHP version to 7.3 solved the problem.

Ayenew Yihune
  • 1,059
  • 13
  • 19
1

Try this Hope it will help You

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


    $insert_array = [
                'name' => $request->name,
                'email' => $request->email,
                'password' => Hash::make($request->password)
            ];

    User::create($insert_array );

    return redirect()->route('admin.pages.users.index')
        ->with('success','User created successfully');
}
void
  • 915
  • 8
  • 20
1

I was facing the same problem, after debugging I found my smtp credentials was not working properly, email sending modules was not working that why I was getting this error, after fixing the credentials my code starts working properly and exception get disappear.

I suggest you to check your smtp credentials and make your you turn on less secure app setting.

Shoaib Rehan
  • 526
  • 6
  • 16
  • turning on my less secure app setting worked for me, it appeared that my email provider turned it off because of multiple failed log attempts. – kapitan Nov 11 '21 at 00:46