PHP code example of mehdirajabi / filterable

1. Go to this page and download the library: Download mehdirajabi/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/ */

    

mehdirajabi / filterable example snippets


use Mehdirajabi\Filterable\Filterable;

class User extends Model
{
    use Filterable;
}

class UserController extends Controller
{
    public function index()
    {
        return User::filter()->actived()->get();
    }
}

http://test.com/api/user/users?filterColumns[0]=name&filterValues[0]=Alex

use Mehdirajabi\Filterable\Filterable;

class User extends Model
{
    use Filterable;

    public function profile()
    {
        return $this->hasOne(UserProfile::class);
    }
}

http://test.com/api/user/users?filterColumns[0]=profile.sex&filterValues[0]=male

use Mehdirajabi\Filterable\Operators\FilterEqual;

class User extends Model
{
    protected $filterMode = [
        'status' => FilterEqual::class
    ];
}

use Mehdirajabi\Filterable\Operators\FilterBetween;

class UserController extends Controller
{
    public function index()
    {
        return User::filter(['id' => FilterBetween::class])->paginate(100);
    }
}

use Mehdirajabi\Filterable\Operators\FilterBetween;

class User extends Model
{
    protected $filterMode = [
        'created_at' => FilterBetween::class
    ];
}

http://test.com/users?filterColumns[0]=created_at&filterValues[0]=2023-06-23 00:00:00, 2023-06-24 23:59:59