DEV Community

Kerry Owston
Kerry Owston

Posted on

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.

Top comments (1)

Collapse
 
snehalkadwe profile image
Snehal Rajeev Moon

Great!! ❤️

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay