You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a project i'm working on I want to be able to scope the query done to retrieve modesl by the implicit binding. At the moment it's not easy to add a condition based on request attributes (set from other middlewares).
A solution would be to pass the request as an additional parameter to resolvers.
Proposed signature
publicfunction resolveRouteBinding($value, $field = null, Request$request = null)
public function resolveChildRouteBinding($childType, $value, $field, Request$request)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For a project i'm working on I want to be able to scope the query done to retrieve modesl by the implicit binding. At the moment it's not easy to add a condition based on request attributes (set from other middlewares).
A solution would be to pass the request as an additional parameter to resolvers.
Proposed signature
To pass this extra parameter the ImplicitRouteBinding would need to be changed https://github.com/laravel/framework/blob/8.x/src/Illuminate/Routing/ImplicitRouteBinding.php#L21 causing a breaking change
Current alternatives
If a previous middleware set an attribut in the request and the resolver needs it, we have currently 3 solutions
The request() function (global is not good :( )
Using the magic method request() we can retrieve the request from a model.
Replacing the SubstituteBinding Middleware (too much copy / paste, harder to maintain)
A custom middleware could be a solution but you have to copy / paste the SubstituteBinding to replace the logic you want.
Route::bind()
Another solution is to use Route::bind but it's limited (we can't catch every parameter neither use condition on the model type)
Beta Was this translation helpful? Give feedback.
All reactions