'Explain this with example

HP@LAPTOP-ASEAM8KR MINGW64 ~/Desktop/udemy_laravel/blog

$ php artisan tinker

Psy Shell v0.11.2 (PHP 8.1.4 — cli) by Justin Hileman

$posts = App\Models\Post::create([ 'user_id'=> 0, 'title'=>"this is a cat", 'content'=>"cat is a pet animal" ]);

Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert i

nto posts (title, content, updated_at, created_at) values (this is a cat, cat is a pet animal, 2022-05-11 20:43:23, 2022-05-11 20:43:23

))'

$posts = App\Models\Post::insert([ 'user_id'=> 0, 'title'=>"this is a cat", 'content'=>"cat is a pet animal" ]);

but this command insert the data in the database file post table without add user_id in the fillable property. How can possible? please explain......i am only change after the scope resolution operator insert in the place of create.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source