1. Go to this page and download the library: Download mjedari/larafilter 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/ */
mjedari / larafilter example snippets
...
public function apply(Builder $builder)
{
return $builder->where('country', $this->value);
}
...
// All registered filtered are available through this method:
User::filter()->get();
// Only Specific registered filter is available and executable:
User::filterThrough([Country::class])->get();
namespace App\Filters;
use Illuminate\Database\Eloquent\Builder;
use Mjedari\Larafilter\Filters\FilterContract;
class Active extends FilterContract
{
public function apply(Builder $builder)
{
// TODO: Implement apply() method.
}
public function options()
{
// TODO: Implement options() method.
}
/*
* Set rules on the query string
*/
public function rules()
{
return [
//
];
}
}
public function apply(Builder $builder)
{
return $builder->where('avtive', $this->value);
}
class User extends Authenticatable
{
use Filterable;
.
.
.
use App\Filters\Active;
use App\Filters\City;
class User extends Authenticatable
{
use Filterable;
protected static $filters = [
Active::class,
City::class
];
.
.
.