Skip to content

Commit 1b70bef

Browse files
committed
fix casing issue with guarded
1 parent 27283b6 commit 1b70bef

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function isFillable($key)
163163
*/
164164
public function isGuarded($key)
165165
{
166-
return in_array($key, $this->getGuarded()) || $this->getGuarded() == ['*'];
166+
return $this->getGuarded() == ['*'] || ! empty(preg_grep('/^'.preg_quote($key).'$/i', $this->getGuarded()));
167167
}
168168

169169
/**

tests/Integration/Database/EloquentModelTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ protected function setUp(): void
2929
});
3030
}
3131

32+
public function testCantUpdateGuardedAttributesUsingDifferentCasing()
33+
{
34+
$model = new TestModel2;
35+
36+
$model->fill(['ID' => 123]);
37+
38+
$this->assertNull($model->ID);
39+
}
40+
3241
public function testUserCanUpdateNullableDate()
3342
{
3443
$user = TestModel1::create([

0 commit comments

Comments
 (0)