mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
* Add support for protected Attribute accessors * Fix formatting * Prevent accessors methods marked as private from being added * Exclude specific accessors based on trait instead of class * Add changelog entry * Add clarifying comment * Fix accessor attributes not working on PHP < 8.1 * Reintroduce method variable to reduce PR clutter * Change variable name to reduce PR clutter * Update CHANGELOG.md --------- Co-authored-by: Barry vd. Heuvel <[email protected]> Co-authored-by: Barry vd. Heuvel <[email protected]>
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Attributes\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Simple extends Model
|
|
{
|
|
protected function name(): Attribute
|
|
{
|
|
return new Attribute(
|
|
function (?string $name): ?string {
|
|
return $name;
|
|
},
|
|
function (?string $name): ?string {
|
|
return $name === null ? null : ucfirst($name);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* ide-helper does not recognize this method being an Attribute
|
|
* because the method has no actual return type;
|
|
* phpdoc is ignored here deliberately due to performance reasons and also
|
|
* isn't supported by Laravel itself.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
|
*/
|
|
protected function notAnAttribute()
|
|
{
|
|
return new Attribute(
|
|
function (?string $value): ?string {
|
|
return $value;
|
|
},
|
|
function (?string $value): ?string {
|
|
return $value;
|
|
}
|
|
);
|
|
}
|
|
}
|