File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
src/Illuminate/Database/Eloquent Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -441,7 +441,9 @@ public function fill(array $attributes)
441
441
{
442
442
$ totallyGuarded = $ this ->totallyGuarded ();
443
443
444
- foreach ($ this ->fillableFromArray ($ attributes ) as $ key => $ value ) {
444
+ $ fillable = $ this ->fillableFromArray ($ attributes );
445
+
446
+ foreach ($ fillable as $ key => $ value ) {
445
447
// The developers may choose to place some attributes in the "fillable" array
446
448
// which means only those attributes may be set through mass assignment to
447
449
// the model, and all others will just get ignored for security reasons.
@@ -455,6 +457,14 @@ public function fill(array $attributes)
455
457
}
456
458
}
457
459
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
+
458
468
return $ this ;
459
469
}
460
470
Original file line number Diff line number Diff line change @@ -1291,10 +1291,14 @@ public function testGuarded()
1291
1291
$ model = new EloquentModelStub ;
1292
1292
$ model ->guard (['name ' , 'age ' ]);
1293
1293
$ model ->fill (['Foo ' => 'bar ' ]);
1294
+
1295
+ Model::preventSilentlyDiscardingAttributes (false );
1294
1296
}
1295
1297
1296
1298
public function testFillableOverridesGuarded ()
1297
1299
{
1300
+ Model::preventSilentlyDiscardingAttributes (false );
1301
+
1298
1302
$ model = new EloquentModelStub ;
1299
1303
$ model ->guard ([]);
1300
1304
$ model ->fillable (['age ' , 'foo ' ]);
You can’t perform that action at this time.
0 commit comments