I created a mutator in model class as follows:
public function setFileDataAttribute($value)
{
if (is_null($value)) {
$value = [];
}
return $value;
}
The corresponding field is : file_data. Catsts and fillables are also set:
protected $casts = [
"created_at" => "datetime:Y-m-d H:i",
"file_data" => "array",
];
protected $attributes = [
"file_data" => [],
];
I have really tried everything, but it is simply not called (I have dd-ed it - nothing) Anyone, any idea?
Update: The class is (simplified):
class XXX extends Model
{
use HasFactory;
use SoftDeletes;
protected $fillable = [
"name",
"cost_type",
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
"file_data" => "array",
];
protected $attributes = [
"file_data" => [],
];
public function setFileDataAttribute($value)
{
if (is_null($value)) {
$value = [];
}
return $value;
}
}