I have an Enum like:
<?php
namespace App\Models\helpers\Enums;
enum ComissionamentoVendedor: string
{
case Faturamento = 'No faturamento';
case Pagamento = 'Após o pagamento pelo cliente';
}
And I have a model that uses this Enum
...
public $casts = [
'comissionamento_momento' => ComissionamentoVendedor::class,
];
...
But when I try to save it I get an error:
$vendedor = new Vendedor;
$vendedor->fill($atributos);
$vendedor->save();
The error is ErrorException: Attempt to read property "value" on string
It happens on the file vendor/illuminate/database/Eloquent/Concerns/HasAttributes.php:951
protected function setEnumCastableAttribute($key, $value)
{
// $value here is a string, a valid value from ComissionamentoVendedor Enum, sent by the frontend but looks like Laravel expects to be an Enum
$this->attributes[$key] = isset($value) ? $value->value : null;
}
Am I doing something wrong? I'm actually using Lumen 8.3.3.
$atributos, contain?