Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 16, 2024 05:47 pm GMT

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

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To