laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

Inject API Resources in controller. #935

Open montyclt opened 6 years ago

montyclt commented 6 years ago

Hello all!

I thought it might be a good idea to implicit inject an API Resource in Controller like model does.

public function show(UserResource $user)
{
    return $user;
}

When any User with the given ID exists, retrieve the model, and instance the type-hinted API resource. If any user with the ID exists, throws ModelNotFoundException.

What is your opinion?

sisve commented 6 years ago

No.

How would my UserListEntryResource even now to look for the User model? How would the model binding system connect the two?

michaeldyrynda commented 6 years ago

If you (always) wanted to return an API resource, you might consider just using explicit route mode binding instead.