Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Resource Endpoints Laravel Package

spatie/laravel-resource-endpoints

Abandoned package that adds controller-based “links” and collection “meta” links to Laravel API Resources. Automatically generates URLs for actions like index/show/edit/update/delete, so resources can expose REST endpoints without manually building routes.

View on GitHub
Deep Wiki
Context7

title: Merging links weight: 5

When creating a single resource like UserResource::make($user) you not only want the links tied to that resource but also the collection links for that resource. In this case next to the show, edit, update and delete links you also want the index, create and store links in your resource.

This can be done by merging the collection links with the single resource links like so:

class UserResource extends JsonResource
{
    use HasLinks;

    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'links' => $this->links(UsersController::class)->withCollectionLinks(),
        ];
    }
}

The UserResource in a response will now look like this:

{
   "data":[
      {
         "id":1,
         "name": "Ruben Van Assche",
         "links": {
            "show": "https://laravel.app/users/1",
            "edit": "https://laravel.app/users/1/edit",
            "update": "https://laravel.app/users/1",
            "delete": "https://laravel.app/users/1",
            "index": "https://laravel.app/users",
            "create": "https://laravel.app/users/create",
            "store":  "https://laravel.app/users"
         }
      }
   ]
}

Automatically merge collection links

Calling withCollectionLinks on every resource can be a bit tedious. That's why when you include the Spatie\ResourceLinks\HasMeta we'll not only add the meta helper but also automatic link merging when you would make a single resource.

Let's have a look, now when creating a single resource like so:

UserResource::make($user);

You would get all the links: show, edit, update, delete, index, create and store. This will only work when making a single resource, collection resources will have their collection links in the meta section.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport