Yes, you can override the relationship name for scoped routes by defining a resolveChildRouteBinding method on the parent model. This method should return the child model instance based on the given route key name.
Here's an example implementation for the parent model:
class ParentModel extends Model
{
public function resolveChildRouteBinding($childType, $value, $field)
{
if ($childType === 'logs') {
return $this->logs()->where('id', $value)->firstOrFail();
}
return parent::resolveChildRouteBinding($childType, $value, $field);
}
public function logs()
{
return $this->hasMany(Log::class);
}
}
In this example, we're checking if the child type is logs, and if so, we're returning the child model instance based on the id route parameter. If the child type is not logs, we're calling the parent implementation of resolveChildRouteBinding.
Note that we're assuming that the child model has an id primary key. If your child model uses a different primary key, you'll need to adjust the where clause accordingly.
With this implementation, you should be able to use the Route::apiResource('stations.logs', ...)->scoped() method with your custom relationship name.