PHP code example of achillesp / laravel-filterable
1. Go to this page and download the library: Download achillesp/laravel-filterable 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/ */
achillesp / laravel-filterable example snippets
use Achillesp\Filterable\Filterable;
class Post extends Eloquent
{
use Filterable;
}
use Achillesp\Filterable\Filters;
class PostFilters extends Filters
{
protected $filters = ['category', 'published'];
protected function category(int $categoryId)
{
return $this->builder->where('category_id', $categoryId);
}
protected function published(bool $isPublished)
{
return $this->builder->where('is_published', $isPublished);
}
}
public function search(Request $request)
{
$filters = new PostFilters($request);
$posts = Post::filter($filters)->get();
return $posts;
}