tomatophp/filament-api

Resource API Generator
Generate JSON APIs from your Filament resources with a single line of code.
Version Compatibility
| Plugin | Filament | Laravel | PHP |
|---|---|---|---|
| 1.x | 3.x | 10.x / 11.x | 8.1+ |
| 5.x | 5.x | 12.x / 13.x | 8.2+ |
Installation
The APIs list page keeps the generated endpoints in an in-memory SQLite table, so the pdo_sqlite PHP extension is required.
composer require tomatophp/filament-api
php artisan filament-api:install
To list the generated endpoints in your panel, register the plugin in /app/Providers/Filament/AdminPanelProvider.php:
->plugin(\TomatoPHP\FilamentApi\FilamentAPIPlugin::make())
The endpoints use the auth:sanctum middleware by default. Install Laravel Sanctum (php artisan install:api) or change default_middleware in config/filament-api.php.
Screenshots

Usage
Add the trait to your resource pages:
use Filament\Resources\Pages\ListRecords;
use TomatoPHP\FilamentApi\Traits\InteractWithAPI;
class ListPosts extends ListRecords
{
use InteractWithAPI;
}
That's it, the API is available under /api/{slug}. Each page type adds its endpoints:
| Page | Endpoints |
|---|---|
ListRecords |
GET /api/{slug} (list, ?search= and ?page=), DELETE /api/{slug}/{id} |
ManageRecords |
all five endpoints |
CreateRecord |
POST /api/{slug} |
EditRecord |
PUT /api/{slug}/{id} |
ViewRecord |
GET /api/{slug}/{id} |
- The list returns the visible columns of the resource table, searches its searchable columns and uses its default sort.
Relationship columns such as
author.nameare eager loaded and searchable. - Create and update validate the request with the rules of every field of the resource form (fields inside sections, tabs and grids included) and save only the form fields.
- Queries go through the resource
getEloquentQuery(), so scopes, soft deletes and tenancy filters apply. - When the model has a policy, the
viewAny,view,create,updateanddeleteabilities are checked for the API user. - The routes point at a controller, so
php artisan route:cacheworks.
Responses look like {"status": "success", "message": "OK", "data": ...}; errors return {"status": "error", "message": "..."}
with the status code (404, 403, and 422 with an errors object for validation).
Customize your API
Override these methods on the page:
// Return a JSON resource from the list, show, store and update endpoints
public static function getFilamentAPIResource(): ?string
{
return PostResource::class;
}
// The middleware of the endpoints
public static function getFilamentAPIMiddleware(): array
{
return ['auth:sanctum'];
}
// The endpoint slug, defaults to the resource slug
public static function getFilamentAPISlug(): ?string
{
return 'articles';
}
// The form used to validate and save the store and update endpoints
public static function getFilamentAPIForm(Schema $schema): Schema
{
return static::getResource()::form($schema);
}
// The table used to shape the list endpoint
public static function getFilamentAPITable(Table $table): Table
{
return static::getResource()::table($table);
}
Publish Assets
php artisan vendor:publish --tag="filament-api-config"
Testing
composer test
Other Filament Packages
Checkout our Awesome TomatoPHP
Related Packages
Send Notification to discord channel Webhook using native FilamentPHP Notificati...
Helps building nice, normalized and easy to consume Laravel REST API.