Páginas · Laravilt
REST API
Expose a resource as a REST API and show it in the table's API view.
A resource can expose its records as a REST API. Override api() on the resource to enable it:
php
The panel registers routes under /{panel}/api/{resource}:
| Operation | Method | Toggle |
|---|---|---|
| List | GET /{panel}/api/{resource} | list() |
| Show | GET /{panel}/api/{resource}/{id} | show() |
| Create | POST /{panel}/api/{resource} | create() |
| Update | PUT /{panel}/api/{resource}/{id} | update() |
| Delete | DELETE /{panel}/api/{resource}/{id} | delete() |
| Bulk delete | POST (takes ids) | bulkDelete() |
Every operation uses auth:sanctum unless you change it. The list endpoint accepts search, sort, direction, and the filters you allow.
Operations and middleware
php
Query options and validation
php
validationRequest(), createValidationRequest(), and updateValidationRequest() accept a FormRequest class instead.
Columns
| Method | Description |
|---|---|
type(), format(), nullable(), enum() | Schema type information |
readable(), writable(), creatable(), updatable(), writeOnly() | Read/write access |
sortable(), filterable(), searchable() | Query capabilities |
relationship(), nestedColumns() | Related data |
transformUsing(), castAs(), default() | Value handling |
description(), example() | Documentation |
Table API view
On the table itself, api() turns on the API view and tester for that table:
php
OpenAPI
ApiResource can describe itself: toOpenApi(), toOpenApiJson(), and toOpenApiYaml().
Custom endpoints can be added with ->actions([ApiAction::make('approve')->post()->action(fn ($record) => ...)]).