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.
Sometimes a more fine-grained control is needed to construct links. Let's say you want to prefix a set of links, change the name of an link, or specify which links to include. That's where link groups come into place. You can now create a resource with controller link as such:
class UserResource extends JsonResource
{
use HasLinks;
public function toArray($request)
{
return [
'links' => $this->links(function (Links $links) {
$links->controller(UsersController::class);
}),
];
}
}
Off course it is possible to use link groups with collection links:
class UserResource extends JsonResource
{
use HasLinks;
public static function collection($resource)
{
return parent::collection($resource)->additional([
'meta' => [
'links' => self::collectionLinks(function (Links $links) {
$links->controller(UsersController::class);
})
],
]);
}
}
In the following sections we'll explain which link types you can create in an link group.
How can I help you explore Laravel packages today?