Creating an API resource from a table/model with no primary key

Viewed 29

I am working on a database that I cannot mutate, and in the shortest explanation possible, it has a pivot table that can be accessed by combining two other table IDs, and then from there I can locate a 4th table's record.

The front end will have access to the first two IDs, meaning that I can locate the pivot ID, and then pull the last table's content with something like

select * from needed_table where pivot_table_id = (
    select id from pivot_table where user_id = 123 and other_table_id = 890
);

I would like to be able to set a single route, Route::apiResource('user/{userId}/other/{otherTableId}/needed', NeededController::class);, but I feel like resources require an ID to populate the store, destroy, update functions, is that right?

Is there a way to modify the resource's sql such that it isn't looking for a primary key on those functions, but instead the above SQL? I am assuming not, as I have searched all day and haven't found anything.

Thanks in advance, even if no.

0 Answers
Related