<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rafflesargentina / l5-filterable-sortable example snippets
php
namespace App\Filters;
use RafflesArgentina\FilterableSortable\QueryFilters;
class ArticleFilters extends QueryFilters
{
public function title($query)
{
return $this->builder->where('title', 'LIKE', '%'.$query.'%');
}
public function author($query)
{
return $this->builder->where('user_id', $query);
}
public function category_id($query)
{
return $this->builder->where('category_id', $query);
}
}
php
namespace App\Sorters;
use RafflesArgentina\FilterableSortable\QuerySorters;
class ArticleSorters extends QuerySorters
{
// These properties are optional:
protected static $orderKey = 'orden'; // Fallback value is 'order'
protected static $orderByKey = 'ordenarPor'; // Fallback value is 'orderBy'
// And there are mandatory:
protected static $defaultOrder = 'asc';
protected static $defaultOrderBy = 'title';
public function title()
{
return $this->builder->orderBy('title', $this->order());
}
public function published_at()
{
return $this->builder->orderBy('updated_at', $this->order())
->orderBy('title', $this->order());
}
}