来自资源的Laravel Nova访问相关模型ID

时间:2019-01-10 12:22:28

标签: laravel laravel-nova

具有:

Listing:
id
user_id
...


ListingTranslation:
id
listing_id
language_id
...

Language
id
iso_code
...

One to Many Relationship between Listing and ListingtTranslation

Listing hasMany ListingTranslation
ListingTranslation belongsTo Listing

One to Many Relationship between Language and ListingTranslation

Language hasMany ListingTranslation
ListingTranslation belongsTo Language

我正在寻找一种从listing_id资源访问ListingTranslation的方法。

相关的列表字段在ListingTranslation Resource中声明:

BelongsTo::make(__('Listing'), 'listing', 'App\Nova\Listing'),

目标是能够在Listing Translation Resource中具有可用语言的选择字段,因此Listing只能有一个ListingTranslation用于可用Language。如果用户选择已经为该特定ListingTranslation创建的Language的语言,则“语言选择”字段将显示验证错误。

渴望在我的ListingTranslation资源中加载这种关系:

public static $with = [
    'listing'
];

我可以在标题和字幕方法中使用它。但是,我无法从fields方法访问它:

BelongsTo::make(__('Language'), 'language', 'App\Nova\Language')
                ->rules("unique:listing_translations,language_id,NULL,id,listing_id,{$this->listing->id}"),

0 个答案:

没有答案