spatie/laravel-endpoint-resources
Abandoned package that adds controller/action-based URL links to Laravel API resources and collection meta. Includes traits to generate “show/edit/update/delete” item links and “index/create/store” collection links automatically.
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"
}
}
}
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);
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:
index, update ...)How can I help you explore Laravel packages today?