Skip to content

Commit 0cfb9d1

Browse files
committed
support for laravel 12 scope attributes
1 parent d93d359 commit 0cfb9d1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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)