PHP code example of faisal50x / query-filter

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

    

faisal50x / query-filter example snippets


 public function index($request){
    $query = User::query();
     if(request()->has('status')) {
        $query = $query->where('status', request()->get('status'));
     }
     if(request()->has('role')) {
        $query = $query->where('role', request()->get('role'));
     }
    $users = $query->get();
}
 php

public function index($request, UserFilter $filter){
    //It's nice and clean
    $users = User::filter($filter)->get();
}

// User Filter
use Faisal50x\QueryFilter\QueryFilter;

class UserFilter extends QueryFilter {

    public function status($query, $status){
        return $query->whereStatus($status);
    }
    
    public function role($query, $role){
        return $query->whereRole($role);
    }
    
}