From 1b70bef5fd7cc5da74abcdf79e283f830fa3b0a4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 5 Aug 2020 14:38:51 -0500 Subject: [PATCH] fix casing issue with guarded --- .../Database/Eloquent/Concerns/GuardsAttributes.php | 2 +- tests/Integration/Database/EloquentModelTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php index b9095c0480c7..04ea61db37f4 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php @@ -163,7 +163,7 @@ public function isFillable($key) */ public function isGuarded($key) { - return in_array($key, $this->getGuarded()) || $this->getGuarded() == ['*']; + return $this->getGuarded() == ['*'] || ! empty(preg_grep('/^'.preg_quote($key).'$/i', $this->getGuarded())); } /** diff --git a/tests/Integration/Database/EloquentModelTest.php b/tests/Integration/Database/EloquentModelTest.php index 751e280b9ddf..7564835d3fa9 100644 --- a/tests/Integration/Database/EloquentModelTest.php +++ b/tests/Integration/Database/EloquentModelTest.php @@ -29,6 +29,15 @@ protected function setUp(): void }); } + public function testCantUpdateGuardedAttributesUsingDifferentCasing() + { + $model = new TestModel2; + + $model->fill(['ID' => 123]); + + $this->assertNull($model->ID); + } + public function testUserCanUpdateNullableDate() { $user = TestModel1::create([