From f04e97021209489743e09f2f59e0efc6153a2f23 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:04:46 +0300 Subject: [PATCH 01/11] Update Builder.php --- src/Illuminate/Database/Eloquent/Builder.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index d32a17b207ef..c5938c4c9133 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1507,9 +1507,9 @@ public function onDelete(Closure $callback) * @param string $scope * @return bool */ - public function hasNamedScope($scope) + public function hasScope($scope) { - return $this->model && $this->model->hasNamedScope($scope); + return $this->model && $this->model->hasScope($scope); } /** @@ -1533,7 +1533,7 @@ public function scopes($scopes) // Next we'll pass the scope callback to the callScope method which will take // care of grouping the "wheres" properly so the logical order doesn't get // messed up when adding scopes. Then we'll return back out the builder. - $builder = $builder->callNamedScope( + $builder = $builder->callScope( $scope, Arr::wrap($parameters) ); } @@ -1615,10 +1615,10 @@ protected function callScope(callable $scope, array $parameters = []) * @param array $parameters * @return mixed */ - protected function callNamedScope($scope, array $parameters = []) + protected function callScope($scope, array $parameters = []) { return $this->callScope(function (...$parameters) use ($scope) { - return $this->model->callNamedScope($scope, $parameters); + return $this->model->callScope($scope, $parameters); }, $parameters); } @@ -2227,8 +2227,8 @@ public function __call($method, $parameters) return $callable(...$parameters); } - if ($this->hasNamedScope($method)) { - return $this->callNamedScope($method, $parameters); + if ($this->hasScope($method)) { + return $this->callScope($method, $parameters); } if (in_array(strtolower($method), $this->passthru)) { From 3311e73c91f0cdacf9200c1dc89976511a589f3e Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:06:16 +0300 Subject: [PATCH 02/11] Update Model.php --- src/Illuminate/Database/Eloquent/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 90260a57ca32..9e86727ef241 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1735,7 +1735,7 @@ public function newPivot(self $parent, array $attributes, $table, $exists, $usin * @param string $scope * @return bool */ - public function hasNamedScope($scope) + public function hasScope($scope) { return method_exists($this, 'scope'.ucfirst($scope)) || static::isScopeMethodWithAttribute($scope); @@ -1748,7 +1748,7 @@ public function hasNamedScope($scope) * @param array $parameters * @return mixed */ - public function callNamedScope($scope, array $parameters = []) + public function callScope($scope, array $parameters = []) { if ($this->isScopeMethodWithAttribute($scope)) { return $this->{$scope}(...$parameters); From ccf59439af9bd2eba524cde411e5f5b86fb74c84 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:07:25 +0300 Subject: [PATCH 03/11] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88069f004cf6..93ff3d6dbb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -875,7 +875,7 @@ * [12.x] Added except() method to Model class for excluding attributes by [@vishal2931](https://github.com/vishal2931) in https://github.com/laravel/framework/pull/55072 * [12.x] fix: add TPivotModel default and define pivot property in {Belongs,Morph}ToMany by [@calebdw](https://github.com/calebdw) in https://github.com/laravel/framework/pull/55086 * [12.x] remove `@return` docblocks on constructors by [@browner12](https://github.com/browner12) in https://github.com/laravel/framework/pull/55076 -* [12.x] Add NamedScope attribute by [@shaedrich](https://github.com/shaedrich) in https://github.com/laravel/framework/pull/54450 +* [12.x] Add Scope attribute by [@shaedrich](https://github.com/shaedrich) in https://github.com/laravel/framework/pull/54450 * [12.x] Improve syntax highlighting for stub type files by [@kayw-geek](https://github.com/kayw-geek) in https://github.com/laravel/framework/pull/55094 * [12.x] Prefer `new Collection` over `Collection::make` by [@AhmedAlaa4611](https://github.com/AhmedAlaa4611) in https://github.com/laravel/framework/pull/55091 * [12.x] Fix except() method to support casted values by [@vishal2931](https://github.com/vishal2931) in https://github.com/laravel/framework/pull/55124 From e366c50495be20ee7184d35f0a3a54d26309def3 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:08:17 +0300 Subject: [PATCH 04/11] Update and rename NamedScopeUser.php to ScopeUser.php --- .../Database/Fixtures/{NamedScopeUser.php => ScopeUser.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Integration/Database/Fixtures/{NamedScopeUser.php => ScopeUser.php} (97%) diff --git a/tests/Integration/Database/Fixtures/NamedScopeUser.php b/tests/Integration/Database/Fixtures/ScopeUser.php similarity index 97% rename from tests/Integration/Database/Fixtures/NamedScopeUser.php rename to tests/Integration/Database/Fixtures/ScopeUser.php index d677aefab294..2482d21f3c7e 100644 --- a/tests/Integration/Database/Fixtures/NamedScopeUser.php +++ b/tests/Integration/Database/Fixtures/ScopeUser.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Attributes\Scope; use Illuminate\Database\Eloquent\Builder; -class NamedScopeUser extends User +class ScopeUser extends User { /** {@inheritdoc} */ #[\Override] From a9ef97f99d196b84c5c6d403627baac4da232a83 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:09:52 +0300 Subject: [PATCH 05/11] Update and rename EloquentNamedScopeAttributeTest.php to EloquentScopeAttributeTest.php --- ...copeAttributeTest.php => EloquentScopeAttributeTest.php} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename tests/Integration/Database/{EloquentNamedScopeAttributeTest.php => EloquentScopeAttributeTest.php} (86%) diff --git a/tests/Integration/Database/EloquentNamedScopeAttributeTest.php b/tests/Integration/Database/EloquentScopeAttributeTest.php similarity index 86% rename from tests/Integration/Database/EloquentNamedScopeAttributeTest.php rename to tests/Integration/Database/EloquentScopeAttributeTest.php index 8dfc37c6fa7e..13a8c196991a 100644 --- a/tests/Integration/Database/EloquentNamedScopeAttributeTest.php +++ b/tests/Integration/Database/EloquentScopeAttributeTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\Attributes\DataProvider; #[WithMigration] -class EloquentNamedScopeAttributeTest extends TestCase +class EloquentScopeAttributeTest extends TestCase { protected $query = 'select * from "named_scope_users" where "email_verified_at" is not null'; @@ -24,7 +24,7 @@ protected function setUp(): void #[DataProvider('scopeDataProvider')] public function test_it_can_query_named_scoped_from_the_query_builder(string $methodName) { - $query = Fixtures\NamedScopeUser::query()->{$methodName}(true); + $query = Fixtures\ScopeUser::query()->{$methodName}(true); $this->assertSame($this->query, $query->toRawSql()); } @@ -32,7 +32,7 @@ public function test_it_can_query_named_scoped_from_the_query_builder(string $me #[DataProvider('scopeDataProvider')] public function test_it_can_query_named_scoped_from_static_query(string $methodName) { - $query = Fixtures\NamedScopeUser::{$methodName}(true); + $query = Fixtures\ScopeUser::{$methodName}(true); $this->assertSame($this->query, $query->toRawSql()); } From 8feffaa4c4abafdcca596db029ef921e6093248b Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:10:38 +0300 Subject: [PATCH 06/11] Update DatabaseEloquentLocalScopesTest.php --- tests/Database/DatabaseEloquentLocalScopesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Database/DatabaseEloquentLocalScopesTest.php b/tests/Database/DatabaseEloquentLocalScopesTest.php index d34a510f1e5f..0ebe2ac5aa25 100644 --- a/tests/Database/DatabaseEloquentLocalScopesTest.php +++ b/tests/Database/DatabaseEloquentLocalScopesTest.php @@ -29,10 +29,10 @@ public function testCanCheckExistenceOfLocalScope() { $model = new EloquentLocalScopesTestModel; - $this->assertTrue($model->hasNamedScope('active')); - $this->assertTrue($model->hasNamedScope('type')); + $this->assertTrue($model->hasScope('active')); + $this->assertTrue($model->hasScope('type')); - $this->assertFalse($model->hasNamedScope('nonExistentLocalScope')); + $this->assertFalse($model->hasScope('nonExistentLocalScope')); } public function testLocalScopeIsApplied() From 7c1bfabeb2cda194e0e5a0aaf3915bc8fcf4f82e Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:49:13 +0300 Subject: [PATCH 07/11] Update Builder.php --- src/Illuminate/Database/Eloquent/Builder.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index c5938c4c9133..4362170ed1de 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1533,7 +1533,7 @@ public function scopes($scopes) // Next we'll pass the scope callback to the callScope method which will take // care of grouping the "wheres" properly so the logical order doesn't get // messed up when adding scopes. Then we'll return back out the builder. - $builder = $builder->callScope( + $builder = $builder->callNamedScope( $scope, Arr::wrap($parameters) ); } @@ -1615,10 +1615,10 @@ protected function callScope(callable $scope, array $parameters = []) * @param array $parameters * @return mixed */ - protected function callScope($scope, array $parameters = []) + protected function callNamedScope($scope, array $parameters = []) { return $this->callScope(function (...$parameters) use ($scope) { - return $this->model->callScope($scope, $parameters); + return $this->model->callNamedScope($scope, $parameters); }, $parameters); } @@ -2228,7 +2228,7 @@ public function __call($method, $parameters) } if ($this->hasScope($method)) { - return $this->callScope($method, $parameters); + return $this->callNamedScope($method, $parameters); } if (in_array(strtolower($method), $this->passthru)) { From fdcdc60714b5babaf9b33162ad2afbd3039aae68 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:49:46 +0300 Subject: [PATCH 08/11] Update Model.php --- src/Illuminate/Database/Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 9e86727ef241..ee827eeba699 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1748,7 +1748,7 @@ public function hasScope($scope) * @param array $parameters * @return mixed */ - public function callScope($scope, array $parameters = []) + public function callNamedScope($scope, array $parameters = []) { if ($this->isScopeMethodWithAttribute($scope)) { return $this->{$scope}(...$parameters); From 284af76ac016cfe9c1b08e9c688a1d768cc01604 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 09:58:26 +0300 Subject: [PATCH 09/11] Update EloquentModelScopeTest.php --- tests/Integration/Database/EloquentModelScopeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Database/EloquentModelScopeTest.php b/tests/Integration/Database/EloquentModelScopeTest.php index 8fca382000a7..339479170728 100644 --- a/tests/Integration/Database/EloquentModelScopeTest.php +++ b/tests/Integration/Database/EloquentModelScopeTest.php @@ -12,21 +12,21 @@ public function testModelHasScope() { $model = new TestScopeModel1; - $this->assertTrue($model->hasNamedScope('exists')); + $this->assertTrue($model->hasScope('exists')); } public function testModelDoesNotHaveScope() { $model = new TestScopeModel1; - $this->assertFalse($model->hasNamedScope('doesNotExist')); + $this->assertFalse($model->hasScope('doesNotExist')); } public function testModelHasAttributedScope() { $model = new TestScopeModel1; - $this->assertTrue($model->hasNamedScope('existsAsWell')); + $this->assertTrue($model->hasScope('existsAsWell')); } } From e7c831cdaf40d778ed585563f17e02abcfc381e3 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:13:04 +0300 Subject: [PATCH 10/11] Update EloquentScopeAttributeTest.php --- tests/Integration/Database/EloquentScopeAttributeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Database/EloquentScopeAttributeTest.php b/tests/Integration/Database/EloquentScopeAttributeTest.php index 13a8c196991a..234fe45581a6 100644 --- a/tests/Integration/Database/EloquentScopeAttributeTest.php +++ b/tests/Integration/Database/EloquentScopeAttributeTest.php @@ -9,7 +9,7 @@ #[WithMigration] class EloquentScopeAttributeTest extends TestCase { - protected $query = 'select * from "named_scope_users" where "email_verified_at" is not null'; + protected $query = 'select * from "scope_users" where "email_verified_at" is not null'; protected function setUp(): void { @@ -22,7 +22,7 @@ protected function setUp(): void } #[DataProvider('scopeDataProvider')] - public function test_it_can_query_named_scoped_from_the_query_builder(string $methodName) + public function test_it_can_query_scoped_from_the_query_builder(string $methodName) { $query = Fixtures\ScopeUser::query()->{$methodName}(true); @@ -30,7 +30,7 @@ public function test_it_can_query_named_scoped_from_the_query_builder(string $me } #[DataProvider('scopeDataProvider')] - public function test_it_can_query_named_scoped_from_static_query(string $methodName) + public function test_it_can_query_scoped_from_static_query(string $methodName) { $query = Fixtures\ScopeUser::{$methodName}(true); From 7e8711c08821e5d6bfd705e2c34faf6632994bd7 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <92916738+AhmedAlaa4611@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:21:56 +0300 Subject: [PATCH 11/11] Re-run tests