PHP code example of matthenning / eloquent-api-filter
1. Go to this page and download the library: Download matthenning/eloquent-api-filter 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/ */
matthenning / eloquent-api-filter example snippets
use Matthenning\EloquentApiFilter\Controller;
class PersonController extends Controller
{
use UsesDefaultIndexMethodTrait,
UsesDefaultShowMethodTrait,
UsesDefaultStoreMethodTrait,
UsesDefaultUpdateMethodTrait,
UsesDefaultDestroyMethodTrait;
}
public static ?string $resourceName = PersonResource::class;
class PersonResource extends \Matthenning\EloquentApiFilter\Resource
{
public function toArray(Request $request): array
{
return $this->enrich([
'id' => $this->resource->id,
// ... map your fields here
]);
}
}
class PersonController extends Matthenning\EloquentApiFilter\Controller
{
use Matthenning\EloquentApiFilter\Traits\FiltersEloquentApi;
public function index(Request $request)
{
$persons = Person::query();
return $this->filterApiRequest($request, $persons);
}
}
use Matthenning\EloquentApiFilter\EloquentApiFilter;
class PersonController extends Controller
{
public function index(Request $request)
{
$query = Person::query();
$filtered = (new EloquentApiFilter($request, $query))->filter();
return $filtered->get();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.