spatie / enum

Strongly typed enums in PHP supporting autocompletion and refactoring
https://docs.spatie.be/enum/v3/introduction
MIT License
776 stars 67 forks source link

Too few arguments to function Spatie\Enum\Enum::__construct(), 0 passed #117

Closed mscalessio closed 2 years ago

mscalessio commented 2 years ago

Hi there! Something strange is happening. I'm using your package in my project with Laravel and Filament admin:

"laravel/framework": "9.19.0"
"php": "8.1.7"
"filament/filament": "2.13.21",
"spatie/enum": "3.13.0",

I have this model in App/Models/Lot

<?php

namespace App\Models;

use App\Enums\ProcedureType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Lot extends Model
{
    use HasFactory, SoftDeletes;

    protected $casts = [
        'deadline' => 'datetime',
        'procedure_type_code' => ProcedureType::class,
    ];
}

And here's my Enum Class

<?php

namespace App\Enums;

use Spatie\Enum\Enum;
/**
 * @method static self not_specified()
 */

class ProcedureType extends Enum
{
    protected static function values(): array
    {
        return [
            'not_specified' => 0
       ];
    }

    protected static function labels(): array
    {
        return [
            'not_specified' => 'Not specified'
       ];
    }
}

In the db table the item has the correct value procedure_type_code = 0

But when i try to reach the listing page of admin filament for resource Lot, this error happens:

Too few arguments to function Spatie\Enum\Enum::__construct(), 0 passed in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php on line 1589 and exactly 1 expected

Is that something I'm missing guys? Thank you in advance

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days

Gummibeer commented 2 years ago

You have to extend the specific Laravel enum class and not the plain PHP one.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days