-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[12.x] Add NamedScope attribute #54450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
6915a93
1b11b31
df67443
19590d2
d6fc922
6d5aa00
3d3b2cd
9f6db62
90de5cf
19f4804
799451a
ded61f4
ab19b5e
83a21e4
50dbb5a
eb4fc57
2c44cd5
1cf779d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| namespace Illuminate\Database\Eloquent\Attributes; | ||
|
|
||
| use Attribute; | ||
|
|
||
| #[Attribute(Attribute::TARGET_METHOD)] | ||
| class NamedScoped | ||
| { | ||
| /** | ||
| * Create a new attribute instance. | ||
| * | ||
| * @param array|string $classes | ||
| * @return void | ||
| */ | ||
| public function __construct() | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| namespace Illuminate\Tests\Integration\Database; | ||
|
|
||
| use Illuminate\Database\Eloquent\Attributes\NamedScope; | ||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class EloquentModelScopeTest extends DatabaseTestCase | ||
|
|
@@ -19,6 +20,13 @@ public function testModelDoesNotHaveScope() | |
|
|
||
| $this->assertFalse($model->hasNamedScope('doesNotExist')); | ||
| } | ||
|
|
||
| public function testModelHasAttributedScope() | ||
| { | ||
| $model = new TestScopeModel1; | ||
|
|
||
| $this->assertTrue($model->hasNamedScope('existsAsWell')); | ||
| } | ||
| } | ||
|
|
||
| class TestScopeModel1 extends Model | ||
|
|
@@ -27,4 +35,10 @@ public function scopeExists() | |
| { | ||
| return true; | ||
| } | ||
|
|
||
| #[NamedScope] | ||
| public function existsAsWell() | ||
|
||
| { | ||
| return true; | ||
| } | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we need to check if
$methodreturnfalsefor incorrect usage such asabstractmethod orpublic function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In lines 1638 – 1640, we test if the method exists—isn't that enough, meaning do we care about how the method is implemented?