-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to attach a middleware to a specific resource relationship? #630
Comments
Hi! different middleware per resource endpoint - e.g. targeting index - I would use controller middleware. It's been a while since I've done anything in this package as I moved development to the new package. If you can't do: $relations->hasOne('foo')->middleware('bar'); Then your best bet is to use a Laravel route group around the relation, i.e.: Route::middleware('foo')->group(function () use ($relations) {
$relations->hasOne('bar');
}); That'll work. Realise it's not pretty though but it will solve your problem. I've moved all development to the new |
The first example doesn't work. RelationshipsRegistration (and the hasOne/hasMany methods) don't have all of the same functionality as the routes themselves. For your second example, are you suggesting that this might work to add $api->resource('foo')
->relationships(static function (RelationshipsRegistration $relations) {
$relations->hasOne('bar');
$relations->hasMany('buzz');
Route::middleware('example')
->group(function () use ($relations) {
$relations->hasOne('fizz');
});
}); That also does not work, though I may have misunderstood what you were suggesting. I'm not sure how I understand this version of the library is deprecated, but the new version is a new architecture with different dependencies. That makes switching problematic. |
Yeah I get upgrading isn't straight-forward, which is why I still consider this package supported for bug fixes and new versions of Laravel. However, as you can appreciate I only have limited time for open source work, so it makes sense for me to focus that on the newer version. Exceptionally surprised that the second example doesn't work. Not sure why that would be, as wrapping route groups should work. I'd be fine with a |
Given something like:
How can I specify a middleware for the
buzz
relationship independent ofbar
andfizz
(and the main resource)? Something akin to this is what I'm looking to do:On that same topic, is there a way to setup different middleware per resource endpoint? I'd like to be able to target the index separately from the individual item. I have a workaround where I split out the resource into multiple definitions using
->only('index')
but it seems clunky.The text was updated successfully, but these errors were encountered: