Reputation: 1
In the context of Laravel Nova. I have the following tables in a database:
order:
group:
user:
In my index view of order I can easily display a column with user_id using this in my Order Resource:
BelongsTo::make('User ID','Group', 'App\Nova\Group')->display('user_id'),
But how do I display member_id? Pseudo wise:
BelongsTo::make('User ID','Group', 'App\Nova\Group')->display('user_id') --> BelongsTo::make('Member ID','User', 'App\Nova\User')->display('member_id') ?
Any help appreciated - Thanks!
Upvotes: 0
Views: 179
Reputation: 429
Write a specific method in the model and use it:
/**
* Get the user that owns the phone.
*/
public function userId()
{
return $this->belongsTo('App\User', 'foreign_key', 'other_key');
}
And in the resource field, specify this method:
BelongsTo::make('Member ID','userId', 'App\User')
Upvotes: 1