PHP code example of rupadana / filament-api-service
1. Go to this page and download the library: Download rupadana/filament-api-service library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rupadana / filament-api-service example snippets
use Rupadana\ApiService\ApiServicePlugin;
$panel->plugins([
ApiServicePlugin::make()
])
class User extends Model implements HasAllowedFields, HasAllowedSorts, HasAllowedFilters {
// Which fields can be selected from the database through the query string
public function getAllowedFields(): array
{
// Your implementation here
}
// Which fields can be used to sort the results through the query string
public function getAllowedSorts(): array
{
// Your implementation here
}
// Which fields can be used to filter the results through the query string
public function getAllowedFilters(): array
{
// Your implementation here
}
}
namespace App\Filament\Resources\BlogResource\Api\Transformers;
use Illuminate\Http\Resources\Json\JsonResource;
class BlogTransformer extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return $this->resource->toArray();
// or
return md5(json_encode($this->resource->toArray()));
}
}
use App\Filament\Resources\BlogResource\Api\Transformers\BlogTransformer;
class BlogResource extends Resource
{
...
public static function getApiTransformer()
{
return BlogTransformer::class;
}
...
}