PHPackages                             spatie/laravel-resource-links - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. spatie/laravel-resource-links

AbandonedArchivedLibrary

spatie/laravel-resource-links
=============================

Add links to Laravel API resources

1.1.2(5y ago)24040.0k↓33.3%131MITPHPPHP ^7.2|^8.0

Since May 3Pushed 5y ago9 watchersCompare

[ Source](https://github.com/spatie/laravel-resource-links)[ Packagist](https://packagist.org/packages/spatie/laravel-resource-links)[ Docs](https://github.com/spatie/laravel-resource-links)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-resource-links/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (15)Used By (1)

**This package is abandoned: [Laravel resource links two years later](https://rubenvanassche.com/laravel-resource-links-two-years-later/)**

Add links to Laravel API resources
==================================

[](#add-links-to-laravel-api-resources)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f84d68f49c5061e4e97f5ed49eb39136ff592aa1e44f242f0a8074e16442ff3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d7265736f757263652d6c696e6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-resource-links)[![GitHub Workflow Status](https://camo.githubusercontent.com/0fc711dd18c8c7179e91c2c8ed0a149616b675fcbf5315aad53405c2b5938324/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d7265736f757263652d6c696e6b732f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/0fc711dd18c8c7179e91c2c8ed0a149616b675fcbf5315aad53405c2b5938324/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d7265736f757263652d6c696e6b732f72756e2d74657374733f6c6162656c3d7465737473)[![Check & fix styling](https://github.com/spatie/laravel-resource-links/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/spatie/laravel-resource-links/workflows/Check%20&%20fix%20styling/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/67a70b0293172a4a8ce33329769bb2e80a3ffd08d2468ea647a7c3c2b1a32408/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d7265736f757263652d6c696e6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-resource-links)

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:

```
{
   "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"
         }
      }
   ],
   "meta": {
      "links": {
         "index": "https://laravel.app/users",
         "create": "https://laravel.app/users/create",
         "store":  "https://laravel.app/users"
      }
   }
}
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/783fe9e9068e9697d6625822e27836a77bf11ead7907b7c5453b1bc261626118/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7265736f757263652d6c696e6b732e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-resource-links)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Why include links in your resources?
------------------------------------

[](#why-include-links-in-your-resources)

Let's say you're building a single-page application or an application built with [Inertia](https://inertiajs.com), 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
-------------------------

[](#setting-up-resource-links)

We have a dedicated [docs](https://docs.spatie.be/laravel-resource-links/v1/usage/resource-setup/) site for this package.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](https://github.com/spatie/laravel-resource-links/blob/master/CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/laravel-resource-links/blob/master/CONTRIBUTING.md) for details.

### Security

[](#security)

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

Credits
-------

[](#credits)

- [Ruben Van Assche](https://github.com/rubenvanassche)
- [All Contributors](https://github.com/spatie/laravel-resource-links/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/spatie/laravel-resource-links/blob/master/LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 68.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~116 days

Total

12

Last Release

1946d ago

Major Versions

0.0.6 → 1.0.02019-09-27

PHP version history (4 changes)0.0.1PHP ^7.1

0.0.3PHP ^7.3

0.0.4PHP ^7.2

1.1.2PHP ^7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (149 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (42 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (11 commits)")[![sniper7kills](https://avatars.githubusercontent.com/u/5902574?v=4)](https://github.com/sniper7kills "sniper7kills (6 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (3 commits)")[![willemvb](https://avatars.githubusercontent.com/u/1336390?v=4)](https://github.com/willemvb "willemvb (2 commits)")[![lexdewilligen](https://avatars.githubusercontent.com/u/31687602?v=4)](https://github.com/lexdewilligen "lexdewilligen (1 commits)")[![Jamesking56](https://avatars.githubusercontent.com/u/253237?v=4)](https://github.com/Jamesking56 "Jamesking56 (1 commits)")[![divanoli](https://avatars.githubusercontent.com/u/12023205?v=4)](https://github.com/divanoli "divanoli (1 commits)")[![tnorthcutt](https://avatars.githubusercontent.com/u/796639?v=4)](https://github.com/tnorthcutt "tnorthcutt (1 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (1 commits)")

---

Tags

endpointlaravelphpresourcesspatielaravel-resource-links

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-resource-links/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-resource-links/health.svg)](https://phpackages.com/packages/spatie-laravel-resource-links)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[spatie/laravel-sluggable

Generate slugs when saving Eloquent models

1.6k11.5M223](/packages/spatie-laravel-sluggable)[spatie/laravel-settings

Store your application settings

1.5k5.9M72](/packages/spatie-laravel-settings)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
