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

Susank05's avatar

Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into `students` (`name`, `address`, `number`, `updated_at`, `created_at`) values (, , , 2018-12-08 04:19:17, 201

I am new to laravel, and this error is giving me a trouble, please help to get rid of it

welcome.blade.php

div class="form-style-8">

Student Registration

    <input type="submit" value="Add" />
</form>

route******* Route::get('/', 'PostController@store')->name('store');

PostController***************

public function store(Request $request) {

    $student = new students;
    $student->name = $request->input('name');
    $student->address = $request->input('address');
    $student->number= $request->input('number');

    $student->save();




}
0 likes
6 replies
Susank05's avatar

@LJLIZARRAGA - <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request; use App\students; class PostController extends Controller { public function index() { $posts = students::all(); return view('welcome')->with('students',$posts); } public function create() {

    return view('welcome');


}
public function store(Request $request)
{


    $student = new students;
    $student->name = $request->input('name');
    $student->address = $request->input('address');
    $student->number= $request->input('number');

    $student->save();




}

}

this is my postcontroller.php code

successdav's avatar

Check your view, you must have forget the name variable on the input type name or misspelled it somehow

Cronix's avatar

Where's the rest of the form? You're just showing a submit button and a close form tag. Show the whole form including the opening form tag, all fields, and the form cllose tag.

Zenith2012's avatar

Check you have added your db fields to $fillable in your model so they can be updated when you ->save(). I'm new to laravel so could be wrong sorry.

tykus's avatar

The fields do not need to be fillable unless you are mass assigning attributes.

Check that the form inputs have name attributes, they will not be send in the request if there is no name:

<input type="text" name="name">
<input type="text" name="address">
<input type="text" name="number">
``

Please or to participate in this conversation.