diff --git a/resources/views/helper.php b/resources/views/helper.php index 74af90c0e..575af25b8 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -29,7 +29,7 @@ $aliases) : ?> namespace { -getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> getExtendsClass() ?>shouldExtendParentClass()): ?> extends getParentClass() ?> { +getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> getExtendsClass() ?>shouldExtendParentClass()): ?> extends getParentClass() ?> { getMethods() as $method) : ?> getDocComment($s2)) . "\n{$s2}" ?>public static function getName() ?>(getParamsWithDefault() ?>) {getDeclaringClass() !== $method->getRoot()) : ?> @@ -76,7 +76,7 @@ - + namespace { /** diff --git a/resources/views/meta.php b/resources/views/meta.php index ea934d022..54854fbdc 100644 --- a/resources/views/meta.php +++ b/resources/views/meta.php @@ -81,7 +81,7 @@ $argumentsList) : ?> - registerArgumentsSet('', $arg) : ?>', $arg) : ?>,); diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 10c476307..aa389ec9a 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -669,9 +669,11 @@ public function getPropertiesFromMethods($model) $comment = $this->getCommentFromDocBlock($reflection); $this->setProperty($name, null, null, true, $comment); } - } elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes') { + } elseif (!empty($reflection->getAttributes('Illuminate\Database\Eloquent\Attributes\Scope')) || (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes')) { + $scopeUsingAttribute = !empty($reflection->getAttributes('Illuminate\Database\Eloquent\Attributes\Scope')); + //Magic scopeAttribute - $name = Str::camel(substr($method, 5)); + $name = $scopeUsingAttribute ? $method : Str::camel(substr($method, 5)); if (!empty($name)) { $comment = $this->getCommentFromDocBlock($reflection); $args = $this->getParameters($reflection); diff --git a/tests/Console/ModelsCommand/QueryScopes/Models/Comment.php b/tests/Console/ModelsCommand/QueryScopes/Models/Comment.php new file mode 100644 index 000000000..a70e9dfc7 --- /dev/null +++ b/tests/Console/ModelsCommand/QueryScopes/Models/Comment.php @@ -0,0 +1,33 @@ +where('ip_address', '127.0.0.1'); + } + + /** + * @comment Scope using the 'scope' prefix + * @param Builder $query + * @return void + */ + protected function scopeSystem(Builder $query): void + { + $query->where('system', true); + } +} diff --git a/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php index 989a14d66..af379f753 100644 --- a/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php @@ -4,6 +4,49 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models; +use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; + +/** + * + * + * @method static Builder|Comment local() Scope using the 'Scope' attribute + * @method static Builder|Comment newModelQuery() + * @method static Builder|Comment newQuery() + * @method static Builder|Comment query() + * @method static Builder|Comment system() Scope using the 'scope' prefix + * @mixin \Eloquent + */ +class Comment extends Model +{ + /** + * @comment Scope using the 'Scope' attribute + * @param Builder $query + * @return void + */ + #[Scope] + protected function local(Builder $query): void + { + $query->where('ip_address', '127.0.0.1'); + } + + /** + * @comment Scope using the 'scope' prefix + * @param Builder $query + * @return void + */ + protected function scopeSystem(Builder $query): void + { + $query->where('system', true); + } +} +