Model::create
Mass assigns an array of attributes to a new model, saves it, and returns the saved instance.
Model::create(array $attributes = []): staticParameters
| Parameter | Type | Description |
|---|---|---|
$$attributesoptional | array= [] | Column and value pairs to fill onto the new model. Keys absent from $fillable (or listed in $guarded) are discarded before the insert. |
Return value
staticThe newly created model instance, already persisted and with its primary key populated.
Errors
Throws Illuminate\Database\Eloquent\MassAssignmentException when the model is totally guarded ($guarded = ['*']) or when Model::preventSilentlyDiscardingAttributes() is enabled and an attribute is not fillable.
create is new Model, fill and save in one statement. It returns the saved instance, so the auto-increment key and any database defaults refreshed on insert are available immediately.
When to reach for it
Use it when you already have an array of trusted, validated data — typically the output of $request->validated(). When you set attributes one by one, or need to inspect the model before writing it, use save instead.
What trips people up
Mass assignment protection. Every model is guarded by default, so you must declare either $fillable (an allowlist) or $guarded (a blocklist) before create will write anything. The part that generates bug reports is that a key missing from $fillable is silently discarded — no exception, no log line, just a row with a null column. Calling Model::preventSilentlyDiscardingAttributes() in a service provider turns that silence into a MassAssignmentException during local development.
The other surprise is that create fires the full event chain: creating, created, saving, saved. If an observer returns false from creating, the insert is cancelled and you get an unsaved model back. Use createQuietly to skip events, and forceCreate to bypass the fillable check for one call.
Example
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Flight extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = ['name', 'delayed'];
}
// Elsewhere, in a controller...
$flight = Flight::create([
'name' => 'London to Paris',
'delayed' => 1,
]);
echo $flight->id; // 1
echo $flight->name; // London to Paris
var_dump($flight->exists); // bool(true)
var_dump($flight->wasRecentlyCreated); // bool(true)When to use it
- Persist a validated store request in a controller in a single line.
- Seed reference data in a migration or database seeder.
- Create a child record through a relationship, letting Eloquent set the foreign key.
- Build fixture rows in a test without hand-rolling a factory.
Frequently asked questions
Why is Laravel not saving some of my attributes on create()?
Because the missing attributes are not listed in the model's $fillable array, so Eloquent discards them before the insert without raising an error. Add them to $fillable, or call Model::preventSilentlyDiscardingAttributes() locally so the drop throws instead.
What is the difference between create() and save() in Eloquent?
create() takes an array, applies mass assignment rules, saves the model and returns the new instance; save() persists a model whose attributes you have already set individually and returns a boolean. create() is a static shortcut, save() is an instance method.
How do I bypass $fillable for a single create call?
Use forceCreate(), which fills and saves without consulting $fillable or $guarded. Reserve it for hand-written arrays in seeders and commands — using it on request data reintroduces the mass assignment vulnerability the guard exists to prevent.
More examples
The silently discarded attribute
The insert succeeds and the price column is left at its default. Nothing in the logs mentions the dropped key, which is why this reads as "Eloquent is not saving my column". Turning on preventSilentlyDiscardingAttributes locally converts the silence into an exception naming the offending attribute.
<?php
use App\Models\Flight;
// $fillable is ['name', 'delayed'] — 'price' is not listed.
$flight = Flight::create([
'name' => 'London to Paris',
'price' => 99,
]);
echo $flight->name; // London to Paris
var_dump($flight->price); // NULL — the key was dropped before the insert
// In AppServiceProvider::boot(), make this loud during development:
// Model::preventSilentlyDiscardingAttributes($this->app->isLocal());
// The same create() call now throws MassAssignmentException.Creating through a relationship
Calling create() on the relationship rather than the model sets the foreign key automatically, so user_id never has to appear in the attribute array — and therefore never has to be fillable. This is the safest way to create owned records from request data.
<?php
use App\Models\User;
$user = User::find(1);
$post = $user->posts()->create([
'title' => 'First post',
'body' => 'Hello.',
]);
echo $post->user_id; // 1 — set by the relationship, not by you
echo $post->title; // First post
// Many at once:
$posts = $user->posts()->createMany([
['title' => 'Second', 'body' => '...'],
['title' => 'Third', 'body' => '...'],
]);
echo $posts->count(); // 2Bypassing the guard deliberately
forceCreate writes attributes the guard would normally strip, which is appropriate for seeders and console commands where the array is hand-written, and dangerous for anything derived from a request. createQuietly suppresses model events, useful when an observer would otherwise dispatch notifications for backfilled rows.
<?php
use App\Models\User;
// Ignores $fillable / $guarded for this call only.
$admin = User::forceCreate([
'name' => 'Taylor',
'email' => '[email protected]',
'is_admin' => true,
]);
var_dump($admin->is_admin); // bool(true)
// Creates the row without firing creating/created/saving/saved events.
$quiet = User::createQuietly([
'name' => 'Nuno',
'email' => '[email protected]',
]);
echo $quiet->name; // Nuno
Discussion