An Interest In:
Web News this Week
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
- April 11, 2024
- April 10, 2024
Laravel Collections and Resources
When working with API's I'd been becoming frustrated with the process around creating resources and collections. Sure when creating resources which seemed to follow a different pattern as when creating migrations, controllers, requests and what not.
Previously when creating contact resource I had used:
a make:resource ContactResource
With a being an alias for PHP artisan.
This was fine for the resource but I also needed a collection.
Intuitively I tried:
a make:collection ContactCollection
Which was the wrong way to go about this.
a make:resource --collection ContactColllection
In the given scenario, Laravel knows that it should create both the resource and its associated collection. This distinction ensures that Laravel sets up the necessary files and configurations for both the resource and its collection correctly.
Original Link: https://dev.to/kowston/laravel-collections-and-resources-2653
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To