Download the PHP package othyn/filament-api-resources without Composer
On this page you can find all versions of the php package othyn/filament-api-resources. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package filament-api-resources
Filament API Resources
A Laravel package that enables Filament to work seamlessly with API-backed resources instead of traditional Eloquent models. This package provides all the necessary components to build Filament admin panels that consume REST APIs. The standard approach is to reach for the superb package known as Sushi, but I've found that a bit limiting when it came to supporting the rest of Filaments feature suite, as well as pagination being an awkward solve. So with that in mind, I created this package.
Filament V4 Beta
Exciting news: Over the weekend, the new Filament V4 Beta was released with official support for 'Tables with custom data', allowing API's to be used with "... supporting features like columns, sorting, searching, pagination, and actions."
Their documentation has extensive information on how to implement custom data now officially, including detailed documentation and extensive examples of 'Using an external API as a table data source'.
I was mid way through initial development of this package, but I can't imagine it will be useful for much longer. So with that said, I'm not going to persue this further- so be warned, the code is a bit rough and ready in places. Glad to see upstream support for this use case, well done to the Filament team as always!
Features
- 🚀 API-First: Built specifically for API-backed resources
- 🔄 Livewire Integration: Custom synthesizer for proper Livewire state management
- 📄 Pagination Support: Automatic pagination handling for API responses
- 💾 Caching: Built-in response caching with configurable TTL
- 🛠 Flexible: Configurable response structure and headers
- 🎯 Filament Native: Works with all standard Filament features (tables, forms, actions, etc.)
Installation
Install the package via Composer:
Publish the configuration file:
Configuration
Configure your API settings in config/filament-api-resources.php:
Add the following environment variables to your .env file:
Usage
1. Create an API Model
Extend the BaseApiModel class to create your API-backed models:
2. Create Filament Resource Pages
Use the provided base classes for your Filament resource pages:
List Page:
View Page:
3. Create Your Filament Resource
Create a standard Filament resource that uses your API model:
Important: When using API resources, you must add
->paginated(), and optionally->deferLoading()to not block page loading on the API response, to your table configuration to ensure proper pagination and loading behavior. The pagination will automatically be forwarded to API calls.
Advanced Usage
Custom Response Structure
If your API uses a different response structure, you can customize it per model using dot notation:
Custom Headers per Request
You can add custom headers for specific requests:
Refreshing Data
In your view pages, you can refresh data from the API manually, in the case that you've performed some form of Livewire action on the page and wish to refresh the page state and repaint:
API Response Format
By default, the package expects your API to return responses in Laravel's standard paginated format:
This matches Laravel's default API resource pagination format. You can customize the response structure keys in the configuration file if your API uses a different format.
Pagination Query Parameters
When fetching paginated data, the package automatically sends the following query parameters to your API:
page- The current page number (e.g.,?page=2)per_page- The number of items per page (e.g.,?per_page=15)
These parameter names can be customized in the configuration file:
Error Handling
The package includes built-in error handling for API requests. Failed requests will throw exceptions with detailed error messages. You can catch and handle these in your application as needed.
Debugging API Requests
When debugging API requests, Laravel's default behavior truncates request exception messages which can make it difficult to see the full API response. To get complete error details, you can disable request truncation in your bootstrap/app.php file:
This will ensure you see the complete API response in your logs and error messages, making debugging much easier.
Caching
API responses are automatically cached based on your configuration. You can:
- Set default cache TTL in config
- Override cache TTL per request
- Force cache refresh when needed
- Disable caching by setting
cacheSecondstonull
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
All versions of filament-api-resources with dependencies
filament/filament Version ^3.0
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/pagination Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
livewire/livewire Version ^3.0