Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add lucid make:resource #11

adibhanna started this conversation in Ideas
Feb 19, 2017 · 4 comments · 2 replies
Discussion options

I have this situation were I'm creating a simple resource (mainly for APIs).
Let's say we have an ArticleController. we usually need Features for all methods in the resourceful controller (things like StoreArticleFeature, UpdateArticleFeature...) then a set of default jobs (CreateArticleJob, UpdateArticleJob...) and for validation, we might need an ArticleRequest class.
So, I'm wondering if we can add a command that automate this process, something like lucid make:resource that will create a boilerplate for all those classes.

Let me know what you think.

You must be logged in to vote

Replies: 4 comments 2 replies

Comment options

I totally agreed.

You must be logged in to vote
0 replies
Comment options

Love this! Added to the roadmap 👍

You must be logged in to vote
0 replies
Comment options

Hello guys. I agree too, that is very usefull.

Even though @Mulkave, what I meant for make:resource command was related to this https://laravel.com/docs/8.x/eloquent-resources.
🤭

You must be logged in to vote
1 reply
Comment options

Ah, that's different 😅 also to be taken into consideration!

Comment options

I am wondering if there’s any progress related to API Resources. They were briefly discussed in few places in Slack and here.

I am wondering if someone is using Laravel API Resources in project. Where do you store them? How do you use them? Do you have a "global" job like RespondWithApiResourceJob?

You must be logged in to vote
1 reply
Comment options

It would be best to keep things Laravel-friendly in terms of structure, this is what we try to achieve most with Lucid. Since resource classes are generated in the Http directory they’re best suited to remain there. A RespondWithApiResourceJob is a good idea of course 👍 in that case it gets passed a combination of resource class name and the model. Otherwise, you could create decorator jobs (specialised jobs) to return a resource per domain, but that could become overhead with a lot of models/resources.

As for resources within services, they’d still reside in the Http dir of the corresponding service (e.g. app/Services/Auth/Http/Resources/UserResource.php however, these resources may only be used by the service (in principal) meaning that services will not use each other’s resources. This is beneficial when resources are different from a service to another, but will not work if you want resources to be available app-wide instead of at the service level.

Another approach would be to put resources next to their corresponding models under app/Data, e.g. app/Data/User/User.php and app/Data/User/UserResource.php this allows the entire application to use them (services, domains, etc.).

The reason why Lucid hasn’t adopted one approach is because it depends on the scenario and the personal/team preference. All approaches are equally valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
Converted from issue

This discussion was converted from issue #11 on December 10, 2020 22:11.

AltStyle によって変換されたページ (->オリジナル) /