Closed tanthammar closed 5 years ago
What error message do you get when trying to save with the KeyValue field present on the Nova resource?
I was not able to reproduce your issue. I have a KeyValue field, with a nullable json column type, cast as array
, filled with your example JSON, and the field is working correctly. Make sure you assets are updated using php artisan nova:publish --force
. If you find out a way to reproduce this, please open another issue. Thanks!
Throws "Array to string conversion" when used with "Many-to-Many" relationship.
// Roles
protected $casts = [
'meta' => 'array',
];
public function users()
{
return $this->belongsToMany(User::class)->withPivot('meta');
}
// Users
protected $casts = [
'meta' => 'array',
];
public function roles()
{
return $this->belongsToMany(Role::class)->withPivot('meta');
}
// Nova User Resource
BelongsToMany::make('Roles')
->fields(function () {
return [
KeyValue::make('Meta')->rules('json'),
]
});
Try
protected $casts = [
'meta' => 'collection',
];
tried everything but still getting the same error -- array to string conversion
but i tried the same thing on another resource file and it's working fine .
Same here, tried collection, array, and AsArrayObject::class casting on the pivot model, still won't work. Latest Nova version, and Laravel 9+, trying to cast to a json field on a postgres DB.
Description:
Trying to use KeyValue Field as documented.
Steps To Reproduce:
Existing data stored in
meta
, MySql typeJSON
field:On Model
On Nova Resource