jeudi 15 mars 2018

Laravel request helper in URL to get ID / Resource ID

I'm working on a Laravel 5.6 app and have the following two API routes:

Route::resource('/partners', 'API\Partners\PartnersController');

Route::resource('/partners/{id}/sales-team', 'API\Partners\SalesTeamController');

In both of the controllers I am referencing a custom middleware 'VerifyUserOwnsTeam' in the construct method.

To get the resource ID from the request in the middleware I previously had:

$request->route('partner')

This worked a URL such as:

/api/partners/1

However, I am now calling a new end point such as:

/api/partners/1/sales-team

In my middleware the request route param for partner is null. If I change the reference to be:

$request->route('id')

Then it works for the latter endpoint, but fails on the first for a null value.

Any idea how to get this consistent?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire