You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fill() method in Illuminate\Database\Eloquent\Model checks if attribute is fillable or not guarded. But isGuarded() in Illuminate\Database\Eloquent\Concerns\GuardsAttributes trait checks if column isGuardableColumn() an that method checks if column is in static::$guardableColumns, which is column listing from database (it is not well documented for isFillable() method). But static::$guardableColumns is only loaded once if not set and won´t update after running migration, if more migrations are migrated during one run of MigrateCommand command.
static::$guardableColumns should be updated after running Schema::table migration.
static::$guardableColumns could be moved to Illuminate\Database\Eloquent\Concerns\HasAttributes trait, renamed to $databaseColumns and checked in fill method in Illuminate\Database\Eloquent\Model class separately before $this->isFillable($key) checking for better readibility.
Steps To Reproduce:
Create migration for table items and create model Item with guarded property id protected $guarded = ['id'];
Create migration, which adds new column to existing table
Schema::table('items', function (Blueprint $table) {
$table->string('slug');
});
Create another migration which creates new models of Item, fills all attributes including slug and saves.
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as separate commits on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
laravel new bug-report --github="--public"
Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.
When created new repository with current version of laravel framework, I could not reproduce the issue. I have found it was already fixed in newer version of laravel (#39880)
Description:
fill() method in Illuminate\Database\Eloquent\Model checks if attribute is fillable or not guarded. But isGuarded() in Illuminate\Database\Eloquent\Concerns\GuardsAttributes trait checks if column isGuardableColumn() an that method checks if column is in static::$guardableColumns, which is column listing from database (it is not well documented for isFillable() method). But static::$guardableColumns is only loaded once if not set and won´t update after running migration, if more migrations are migrated during one run of MigrateCommand command.
static::$guardableColumns should be updated after running Schema::table migration.
static::$guardableColumns could be moved to Illuminate\Database\Eloquent\Concerns\HasAttributes trait, renamed to $databaseColumns and checked in fill method in Illuminate\Database\Eloquent\Model class separately before $this->isFillable($key) checking for better readibility.
Steps To Reproduce:
protected $guarded = ['id'];
Workaround:
The text was updated successfully, but these errors were encountered: