This package is abandoned and no longer maintained. No replacement package was suggested.

Add links to Laravel API resources

1.1.2 2021-01-13 11:27 UTC

This package is auto-updated.

Last update: 2021-04-14 14:34:28 UTC


This package is abandoned: Laravel resource links two years later

Add links to Laravel API resources

Latest Version on Packagist GitHub Workflow Status Check & fix styling Total Downloads

Let's say you have a UsersController with index, show, create, edit, store, update and delete methods and an UserResource. Wouldn't it be nice if you had the URL's to these methods immediately in your UserResource without having to construct them from scratch?

This package will add these links to your resource based upon a controller or actions you define. Let's look at an example of a resource.

class UserResource extends JsonResource
    use Spatie\ResourceLinks\HasLinks;
    use Spatie\ResourceLinks\HasMeta;

    public function toArray($request): array
        return [
            'id' => $this->id,
            'name' => $this->name,
            'links' => $this->links(UsersController::class),

    public static function meta()
        return [
            'links' => self::collectionLinks(UsersController::class),

Now when creating a UserResource collection, you will have all the links from the UserController available:

         "name": "Ruben Van Assche",
         "links": {
            "show": "",
            "edit": "",
            "update": "",
            "delete": ""
   "meta": {
      "links": {
         "index": "",
         "create": "",
         "store":  ""

Support us


We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Why include links in your resources?

Let's say you're building a single-page application or an application built with Inertia, then you have a PHP application running at the backend and a Javascript application at the front. These applications communicate with each other via an api but what if the frontend wants to route a user to another page?

Since routes are defined in the backend, the frontend has no idea where it has to route the user to. We could just write the url's in the javascript code but what if a route is changed? So why not pass these routes from the backend to the frontend? You could just manually write down all these routes, or let this package do that job for you.

Setting up resource links

We have a dedicated docs site for this package.


composer test


Please see CHANGELOG for more information on what has changed recently.


Please see CONTRIBUTING for details.


If you discover any security related issues, please email instead of using the issue tracker.



The MIT License (MIT). Please see License File for more information.