The mock I've created to fill the database with a row does not understand that it needs to cast the data into JSON before storing it to the database. For some reason, when the data from the mock is inserted into the database it skips casting to JSON. So when the logic then fetches the row from the database it returns this error.
json_decode() expects parameter 1 to be string, array given
If I have it as an array in the mock. It will produce this error when we decode in the controller. If I encode it in the mock, it returns the same error. If I encode it in the mock and remove the cast from the model, it works as expected.
Does anyone know how to do this properly?
this is my mock
class SettingMocks
{
public static function getSetting() {
return [
'id' => 1,
'name' => 'Standard',
'settings' => json_encode([
'objective' => "CONVERSIONS",
'gender' => [1,2],
])
];
}
}
this is my model
class Setting extends Model
{
protected $guarded = [];
protected $casts = [
'settings' => 'json',
];
}