Route parameter to model binding #1779
Unanswered
notramo
asked this question in
Feature requests & Ideas
Replies: 1 comment 1 reply
-
This wouldn't really be possible in Lucky because you don't use the Model for doing queries. Since we use a separate object, there wouldn't be a way to tell which one you wanted without other boilerplate. class Employees::Show < ApiAction
get "/employees/:employee_id" do
# We can't just assume you would use EmployeeQuery here without side affects
employee = UserQuery.new.employee_id(1234).first
json(EmployeeSerializer.new(employee))
end
end Though, maybe this could be a good case for a separate shard? Then in that case there's at least an understanding of how things are done... Might be worth looking in to. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Laravel route model binding is very useful in reducing boilerplate.
https://laravel.com/docs/9.x/routing#route-model-binding
How it would work in Lucky?
When a route parameter contains an
_id
suffix, automatically define a method, without the_id
suffix that retrieves and memoize the given instance of a model. E.g. if the route param isemployee_id
, Lucky woud define theemployee
method that retrieves anEmployee
with the given id, and return 404 if not found. It could also check the relationships for nested resources.Beta Was this translation helpful? Give feedback.
All reactions