Skip to content
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -2227,7 +2227,7 @@ public function __call($method, $parameters)
return $callable(...$parameters);
}

if ($this->hasNamedScope($method)) {
if ($this->hasScope($method)) {
return $this->callNamedScope($method, $parameters);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/DatabaseEloquentLocalScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Database/EloquentModelScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
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';
protected $query = 'select * from "scope_users" where "email_verified_at" is not null';

protected function setUp(): void
{
Expand All @@ -22,17 +22,17 @@ 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\NamedScopeUser::query()->{$methodName}(true);
$query = Fixtures\ScopeUser::query()->{$methodName}(true);

$this->assertSame($this->query, $query->toRawSql());
}

#[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\NamedScopeUser::{$methodName}(true);
$query = Fixtures\ScopeUser::{$methodName}(true);

$this->assertSame($this->query, $query->toRawSql());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down