Laravel Model allows two functions for inserting the values to the database table. They are
Create:
User::create([\'id\'=>1,\'name\'=>\'stack\']);
The model does not have an insert
, calling Model::insert
results in a call to (the Query Builder) Builder::insert
through the __call()
magic method which then avoids the Eloquent benefits like setting the timestamps
for created_at
and updated_at
fields.
It also avoids the Mass-assignment protection which Eloquent protects you from inserting unintentional data.
So I would always use create
or setting each field separately (if you need to modify the incoming data) and call save()
on the model instance.