Skip to content
Discussion options

You must be logged in to vote

Mass assignment only works with eloquent models. When calling update on a query builder instance no eloquent model is received and laravel doesn't know whats in the fillable and guarded property.

// Calling update on a builder will simply execute an update query
// -> "update `groups` set `name` = ?, `updated_at` = ? where `id` = ?"
$builder = Group::where('id', $id); // Illuminate\Database\Eloquent\Builder
$builder->update(...);

// When first retrieving an eloquent model a select query will retrieve the data, then hydrate it into an eloquent model
// and then you can do all sorts of stuff, like updating the model
$model = Group::firstWhere('id', $id); // App\Models\Group
$model->update(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hms5232
Comment options

Answer selected by hms5232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants