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.
Next to controllers, you can also add actions to an links group:
class UserResource extends JsonResource
{
use HasLinks;
public function toArray($request)
{
return [
'links' => $this->links(function (Links $links) {
$links->action([UsersController::class, 'create']);
}),
];
}
}
Is possible to specify the parameters for the links:
$links
->action([UsersController::class, 'create'])
->parameters(User::first());
Or prefix the link:
$links
->action([UsersController::class, 'create'])
->prefix('admin');
The name of the action can also be changed:
$links
->action([UsersController::class, 'create'])
->name('build');
Changing the Http verb(POST, GET, …) of the action can be done as such:
$links
->action([UsersController::class, 'create'])
->httpVerb('POST');
How can I help you explore Laravel packages today?