Looses enum casted types if an accessor is defined.
When using only casts it generates the types perfectly. But when we try to define an accessor then it looses the type
namespace App\Models;
use App\Enums\PostType;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {
protected $casts = [
'type'=> PostType::class
];
//Using an accessor makes the type to string
protected function type(): Attribute
{
return Attribute::make(
get: fn(string|PostType $value): string => $value instanceof PostType ? $value->value : $value,
);
}
}
I tried using a property annotation and custom mappings but it seem like the accessor takes priority over them
Ok I found this on the docs that lets me use my custom interface. but since modeltyper is not using the enum cast their is no types generated for that.
public array $interfaces = [
'type' => [
'type' => 'PostType',
],
];
But I don't see anything that generates enum types regardless if they are used in a cast or not
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.