I am developing a Laravel admin using Laravel Nova. I have DB structure:
works
id
device_id
work_type
devices
id
serial_number
device_type_id
device_types
id
device_name
brand_id
brands
id
brand
This is the Work model class
class Work extends Model {
public function device()
{
return $this->belongsTo( device::class );
}
}
This is the Device model class
class Device extends Model {
public function deviceType()
{
return $this->belongsTo( DeviceType::class, 'device_type_id' );
}
}
This is the DeviceType model class
class DeviceType extends Model
{
public function brand()
{
return $this->belongsTo( Brand::class );
}
}
This is my actual Nova resource
class Work extends Resource
{
public function fields(Request $request)
{
return [
BelongsTo::make( 'Serial number', 'device', 'App\Nova\Device' )->searchable()
];
}
}
On the Laravel Nova "Works" index page, I would like something like that: | Work ID | Serial number | Device type | Brand | | -------- | -------------- | ----------- | ------- | | 1234 | 12345678901234 | S20 | Samsung | | 2345 | 99999999999999 | S21 | Samsung |
I have no idea how to display "Device type" and "Brand" columns.
These columns also should be sortable.