Open Jigsaw5279 opened 2 months ago
I want to add to this that it works fine when using sqlite and the error shows on MySql for me.
I've created a repo which shows the error.
There is a dusk TestCase in there which reproduces the error every time.
Facing the same bug, is there any solution, please?
I have the same problem.
I believe the cast just needs to json encode the result. E.g. add this to FlexibleCast or your own Cast that extends FlexibleCast:
use Illuminate\Database\Eloquent\Casts\Json;
public function set($model, string $key, $value, array $attributes)
{
return [$key => Json::encode($value)];
}
The above solution is insufficient. You still need to check whether the value is an iterable:
public function set($model, string $key, $value, array $attributes): mixed
{
if (is_iterable($value)) {
return [$key => json_encode($value)];
}
return $value;
}
Otherwise, things might start to break in unexpected ways.
Adding the following to your model file is sufficient:
protected $casts = [
'column_name' => 'array',
];
Replace 'column_name' with your actual column name in the database.
I've recently upgraded to Laravel 11, and now I can't use FlexFields anymore.
Whenever I'm updating a model with any Flexfield, I get an Exception like this:
I've tried creating the most basic Model copying the docs to see of maybe something else goes wrong:
Model
Resource Fields: