orlyapps / nova-belongsto-depend

Larave Nova BelongsTo Field with Dependcy
MIT License
182 stars 65 forks source link

issue with translatable #69

Open danielschweiger opened 4 years ago

danielschweiger commented 4 years ago

it does not work with

"spatie/laravel-translatable" "spatie/nova-translatable"

Bildschirmfoto 2020-08-16 um 21 03 08

it displays the json from the database.

iveliniliev90 commented 3 years ago

Same problem here! Can you fix this please !

vadimsauzans commented 2 years ago

Found the solution for this using DB's json function. Haven't tested on MySQL, but work fine with Postgresql 13.

NovaBelongsToDepend::make('Group', 'group', GroupsResource::class)
                ->optionsResolve(function ($domain) {
                    return $domain->groups()->get(['id', 'translation->en as name']);
                })->dependsOn('Domain')
                ->required()

It will produce such query:

select
  "id",
  "translation" ->> 'en' as "name"
from
  "groups"
where
  "groups"."domain_id" = 1
  and "groups"."domain_id" is not null