-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
Laravel Version
12.21.0
PHP Version
8.4.1
Database Driver & Version
No response
Description
Depending on how a model is configured to be guarded, inconsistent behaviour results in mass assignment issues.
The problem stems from the GuardsAttributes
trait having two different mechanisms to guard the model.
- $guarded (array default: ['*'])
- $unguarded (boolean default: false)
Steps To Reproduce
Configured a model with an empty $guarded
property, but have the $fillable
populated.
public function testGuardedWithFillableConfig(): void
{
$model = new EloquentModelStub;
$model::unguard();
EloquentModelStub::setConnectionResolver($resolver = m::mock(Resolver::class));
$resolver->shouldReceive('connection')->andReturn($connection = m::mock(stdClass::class));
$connection->shouldReceive('getSchemaBuilder->getColumnListing')->andReturn(['name', 'age', 'foo']);
$model->guard([]);
$model->fillable(['name']);
$model->fill(['name' => 'Leto Atreides', 'age' => 51]);
self::assertSame(
['name' => 'Leto Atreides', 'age' => 51],
$model->getAttributes(),
);
$model::reguard();
}
Metadata
Metadata
Assignees
Labels
No labels