Skip to content

Commit 552fbc2

Browse files
Merge pull request #357 from laravel/laravel-12-scope-attributes
Support for Laravel 12 scope attributes
2 parents 55a209f + 0cfb9d1 commit 552fbc2

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "laravel",
44
"displayName": "Laravel",
55
"description": "Official VS Code extension for Laravel",
6-
"version": "1.0.4",
6+
"version": "1.0.5",
77
"engines": {
88
"vscode": "^1.89.0"
99
},

php-templates/models.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected function getInfo($className)
155155
->toArray();
156156

157157
$data['scopes'] = collect($reflection->getMethods())
158-
->filter(fn($method) => $method->isPublic() && !$method->isStatic() && str_starts_with($method->name, 'scope'))
158+
->filter(fn($method) =>!$method->isStatic() && ($method->getAttributes(\Illuminate\Database\Eloquent\Attributes\Scope::class) || ($method->isPublic() && str_starts_with($method->name, 'scope'))))
159159
->map(fn($method) => str($method->name)->replace('scope', '')->lcfirst()->toString())
160160
->values()
161161
->toArray();
@@ -175,8 +175,8 @@ public function methods()
175175
{
176176
$reflection = new \ReflectionClass(\Illuminate\Database\Query\Builder::class);
177177

178-
return collect($reflection->getMethods(\ReflectionMethod::IS_PUBLIC))
179-
->filter(fn(ReflectionMethod $method) => !str_starts_with($method->getName(), "__"))
178+
return collect($reflection->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED))
179+
->filter(fn(ReflectionMethod $method) => !str_starts_with($method->getName(), "__") || (!$method->isPublic() && empty($method->getAttributes(\Illuminate\Database\Eloquent\Attributes\Scope::class))))
180180
->map(fn(\ReflectionMethod $method) => $this->getMethodInfo($method))
181181
->filter()
182182
->values();

src/templates/models.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ $models = new class($factory) {
155155
->toArray();
156156
157157
$data['scopes'] = collect($reflection->getMethods())
158-
->filter(fn($method) => $method->isPublic() && !$method->isStatic() && str_starts_with($method->name, 'scope'))
158+
->filter(fn($method) =>!$method->isStatic() && ($method->getAttributes(\\Illuminate\\Database\\Eloquent\\Attributes\\Scope::class) || ($method->isPublic() && str_starts_with($method->name, 'scope'))))
159159
->map(fn($method) => str($method->name)->replace('scope', '')->lcfirst()->toString())
160160
->values()
161161
->toArray();
@@ -175,8 +175,8 @@ $builder = new class($docblocks) {
175175
{
176176
$reflection = new \\ReflectionClass(\\Illuminate\\Database\\Query\\Builder::class);
177177
178-
return collect($reflection->getMethods(\\ReflectionMethod::IS_PUBLIC))
179-
->filter(fn(ReflectionMethod $method) => !str_starts_with($method->getName(), "__"))
178+
return collect($reflection->getMethods(\\ReflectionMethod::IS_PUBLIC | \\ReflectionMethod::IS_PROTECTED))
179+
->filter(fn(ReflectionMethod $method) => !str_starts_with($method->getName(), "__") || (!$method->isPublic() && empty($method->getAttributes(\\Illuminate\\Database\\Eloquent\\Attributes\\Scope::class))))
180180
->map(fn(\\ReflectionMethod $method) => $this->getMethodInfo($method))
181181
->filter()
182182
->values();

0 commit comments

Comments
 (0)