Belongs to relationship not working in my Nova application when relationship method name and foreign key prefix are different.
I have two tables, event & client_location with Models Event & ClientLocation
Event Model:
class Event extends Model
{
public function clientLocation()
{
return $this->belongsTo(\App\ClientLocation::class, 'location_id');
}
}
ClientLocation Model:
class ClientLocation extends Model
{
public function events()
{
return $this->hasMany(\App\Event::class, 'location_id');
}
}
Nova Resource fields method for Event:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
BelongsTo::make('clientLocation'),
];
}
Any idea on how to handle this issue?