PHP code example of kevinoo / graphql-laravel-filters
1. Go to this page and download the library: Download kevinoo/graphql-laravel-filters 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/ */
kevinoo / graphql-laravel-filters example snippets
use kevinoo\GraphQL\Queries;
class MyCustomModelQuery extends AbstractPaginateQuery
{
// public const GENERIC_FILTERS = true;
// public const TRASHED_FILTER = true;
// public const MAX_LIMIT_RESULTS = 1000;
protected $attributes = [
'name' => 'Name of Query',
];
public function getGraphQLType(): string
{
return 'Your GraphQL Type';
}
public function args(): array
{
return parent::args() + [
'filters' => [
'type' => GraphQL::type('Your GraphQL FilterInput'),
],
];
}
protected function resolveModelBuilder( array $args ): Builder
{
$builder = YourModel::query();
$order_by = ($args['orders'] ?? []) ?: ['domain'=>'ASC'];
foreach( $order_by as $column => $direction ){
$builder->orderBy($column,$direction);
}
return $builder;
}
protected function getGenericFiltersKeys(): array
{
return [
'your_input_key_1' => 'model_attribute_1', // Input value can be string, int, boolean or array
'your_input_key_2' => new AdvancedSearch('model_attribute_to_apply_advanced_search'),
'your_input_key_3_array' => 'model_attribute_2',
];
}
protected function getPipelineFiltersSteps(): array
{
return parent::getPipelineFiltersSteps() + [
// Add your other custom filters class
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.