Package currently converts relation names to plural snake_case in fields parameters, causing inconsistencies when using singular relation names in API requests.
Suppose that I have the bellow model:
class Task extends Model
{
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function userOwnerTestName(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
}
I would like to request the userOwnerTestName relationship, my first try was do this:
Problem:
Package currently converts relation names to plural snake_case in fields parameters, causing inconsistencies when using singular relation names in API requests.
Suppose that I have the bellow model:
I would like to request the userOwnerTestName relationship, my first try was do this:
api/v1/tasks?include=userOwnerTestName&fields[userOwnerTestName]=id,email&fields[tasks]=user_id
and the response is:
But I was expecting:
If I change the request to:
api/v1/tasks?include=userOwnerTestName&fields[user_owner_test_names]=id,email&fields[tasks]=user_id
it works like a charm! But I need to convert the relationship name to plural and use the snake_case format.
Solution:
Introduce a configuration option to control relation name conversion:
Example Usage: