PHP code example of mjedari / larafilter

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);
}

...

use Filterable;
...

...

protected static $filters = [
    Country::class,
];


// 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
    ];

    .
    .
    .


User::filter()->get();

User::filterThrough([City::class])->get();

Route::get('/?country=germany', function() {
    return User->filter()->get();
});


class CountryFilter extends FilterContract
{
    public static $queryName = 'country';
    .
    .
    .



class Active extends FilterContract
{
 
    public function rules()
    {
        return [
            '


class Active extends FilterContract
{
    
    protected $cast = 'boolean';

    public function rules()
    {
        return [
            //
        ];
    }
bash
php artisan vendor:publish --provider "Mjedari\Larafilter\LarafilterServiceProvider"