19

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 !

12
  • 1
    Does this answer your question? Trying to access array offset on value of type null Commented Feb 12, 2020 at 13:21
  • @NicoHaase: see my edit. Commented Feb 12, 2020 at 13:46
  • try just 'email' => 'required|email|unique:users', Commented Feb 12, 2020 at 13:52
  • @V-K: if just 'email' => 'email' I see error and not work Commented Feb 12, 2020 at 13:56
  • which version php and laravel do you have? Commented Feb 12, 2020 at 13:58

6 Answers 6

30

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

composer update

This works for me

Sign up to request clarification or add additional context in comments.

2 Comments

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
place isset function in vendor/illuminate/support/ServiceProvider.php on line 84 isset($this->app->config['view']) && isset($this->app->config['view']['paths'])
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.

3 Comments

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, It is my pleasure to solve your problem
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!
6

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 ...

2 Comments

A vendor package should never be modified directly, subsequent updates via composer update may overwrite any changes you make.
@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
4

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

Comments

0

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

Comments

0

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.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.