Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mian's avatar
Level 1

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (, , $2y$10$sFHcGna6Q7vofl9.yIqNBOkQ7NzBVKnY3QoNLFUTkezRrqiIE9wRO, 2018-07-17 11:

I am stuck with this error trying to submit a form Can someone help me out, please help

UsersController.php

public function store(Request $request) {

//dd($request->all());


    $user=User::create([
            'name'=>$request->name,
           'email'=>$request->email,
         'password'=>bcrypt('password')
    ]);

     $profile=Profile::create([

'user_id'=>$user->id, 'avatar'=>'uploads/avatars/11.png' ]);

Session::flash('success','User Added Successfull!');

return redirect()->route('users'); }

Create table user

0 likes
5 replies
MaverickChan's avatar

what is in your User Model?

there should be a line :

protected $fillable = ['name','email',.....];

1 like
lostdreamer_nl's avatar

The User model should have that pre setup already.

I'm inclined to think there is no name / email posted in the form.

tykus's avatar

Makes a case for validating your request @mian :

$user=User::create($request->validate([
    'name'=>'required',
    'email'=>'required|unique:users,email,
    'password'=>required
]);

You will get validation error rather than a QueryException.

As @lostdreamer_nl says, there probably is no fields called name and email in the form since both values are empty in the SQL above. Remember that an input must have a name attribute in order to be submitted.

1 like
abhishektrivedi's avatar

Show me your code of following files....

  • add blade form, model, migration

I think the form field name and migration field name does not match

sadiq810's avatar

Your model receives name and email fields as empty and these fields are marked required in the table structure, make sure that you receive both fields with values in the controller from the form.

Please or to participate in this conversation.