Skip to content

Commit eff2275

Browse files
committed
attempt to fix 43893
1 parent 75ec9c3 commit eff2275

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ public function fill(array $attributes)
441441
{
442442
$totallyGuarded = $this->totallyGuarded();
443443

444-
foreach ($this->fillableFromArray($attributes) as $key => $value) {
444+
$fillable = $this->fillableFromArray($attributes);
445+
446+
foreach ($fillable as $key => $value) {
445447
// The developers may choose to place some attributes in the "fillable" array
446448
// which means only those attributes may be set through mass assignment to
447449
// the model, and all others will just get ignored for security reasons.
@@ -455,6 +457,14 @@ public function fill(array $attributes)
455457
}
456458
}
457459

460+
if (count($attributes) !== count($fillable) &&
461+
static::preventsSilentlyDiscardingAttributes()) {
462+
throw new MassAssignmentException(sprintf(
463+
'Add fillable property to allow mass assignment on [%s].',
464+
get_class($this)
465+
));
466+
}
467+
458468
return $this;
459469
}
460470

tests/Database/DatabaseEloquentModelTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,14 @@ public function testGuarded()
12911291
$model = new EloquentModelStub;
12921292
$model->guard(['name', 'age']);
12931293
$model->fill(['Foo' => 'bar']);
1294+
1295+
Model::preventSilentlyDiscardingAttributes(false);
12941296
}
12951297

12961298
public function testFillableOverridesGuarded()
12971299
{
1300+
Model::preventSilentlyDiscardingAttributes(false);
1301+
12981302
$model = new EloquentModelStub;
12991303
$model->guard([]);
13001304
$model->fillable(['age', 'foo']);

0 commit comments

Comments
 (0)