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 Links Laravel Package

spatie/laravel-resource-links

Abandoned package that adds action URLs to Laravel API resources. Generate per-item and collection links (show/edit/update/delete, index/create/store) from a controller or defined actions, so resources include ready-to-use endpoints without manual URL building.

View on GitHub
Deep Wiki
Context7

title: Json structure weight: 6

Want to change how links are structured in your resources? You can use serializers to output links different formats and even write your own custom serializes!

You can specify the serializer to be used in the config file of the package.

On a default installation we use the LinkSerializer:

"links": {
    "index": "https://laravel.app/users",
    "update": "https://laravel.app/users/1",
}

Want to include the http verb of a link? Then take a look at the ExtendedLinkSerializer:

"links": {
    "index": {
        'method': 'get',
        'action': "https://laravel.app/users"
    },
    "update": {
        'method': 'put',
        'action': "https://laravel.app/users/1"     
    },
}

Want prefixes in separate objects? No problem, use the LayeredExtendedLinkSerializer! Normally a prefixed link would look like this

"links": {
    "index": {
        'method': 'get',
        'action': "https://laravel.app/users"
    },
    "actions.update": {
        'method': 'put',
        'action': "https://laravel.app/users/1"     
    },
}

With the LayeredExtendedLinkSerializer it will look like this:

"links": {
    "index": {
        'method': 'get',
        'action': "https://laravel.app/users"
    },
    "actions"{
        "update": {
            'method': 'put',
            'action': "https://laravel.app/users/1"     
        }
    }
}

Using serializers

The default serializer for a project can be set in the resource-links.php config file. If you are using link groups, it is possible to set a serializer specifically for each link:

$links
    ->controller(UsersController::class)
    ->serializer(Spatie\LaravelResourceLinks\Serializers\LayeredExtendedLinkSerializer::class);

Creating your own serializers

You can create serializers by implementing the Spatie\ResourceLinks\Serializers\Serializer interface:

interface Serializer
{
    public function format(LinkContainer $linkContainer): array;
}

The LinkContainer contains information about the link like:

  • name: the name of the link (index, update ...)
  • method: the http verb of the link
  • action: the url of the link
  • prefix: a prefix used by the user for the link
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