Skip to content

Custom model binding #321

@najdias

Description

@najdias

Hi,

I need a little support if i can do what i intend to do.
I have 2 resources "Users" and "Associations" connected by many to many relationship.
I have a route api/v1/users/{user}/associations to return the user associations.
If i use the user id in the call is all ok for instance api/v1/users/1/associations but what i want to do is to be able to send also the "me" word in the {user} binding so that i can check the authenticated user associations..
Normally in Laravel i can do in AppServiceProvider boot method this

Route::bind('user', function ($value) {
    if ($value === 'me') {
        return auth()->user();
    }
    return User::where('id', $value)->firstOrFail();
});

But since JSON:API middleware is able to substitute the resource binding for the route without resorting to Laravel's implementation how can i have a custom model binding?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions