v1.0.2: Focus on specific function under your QueryFilter
stable relsease
Sometime you may want to pass the intended function in your query filter, 🆗 to not pass through them all!
and well!, it might scale your application to run more faster!, because we have focus! right! 👍 🥳
Right now, what you need to do is pass those function as parameter into your ->filter(QueryFilter, ['function-as-string'])
function! 🥳 !, Let take quick example:
Let suppose we have Our QueryFilter class as:
namespace App\Filters;
use Patienceman\QueryFilter;
class AirlineFilter extends QueryFilter {
/**
* search given string from airlines by name
* @param string $query
*/
public function query(string $query){
$this->builder->where('name', 'LIKE', '%' . $query . '%');
}
/**
* Get where code
* @param string $code
*/
public function code(string $code){
$this->builder->where("code", "some example code");
}
/**
* Get where location
* @param string $location
*/
public function location(string $location){
$this->builder->where("location", "not attached");
}
}
So to work with that, you will: 🛑 remember we want query and code
🥽 :
/**
* Get all airlines that are open for ticket
*
* @param AirlineFilter $filter
* @return JsonResponse
*/
public function index(AirlineFilter $filter) {
$airlines = Airline::where('ticket', 'active)
->filter($filter, ['query', 'code'])
->get();
return AirlineResource::collection($airlines);
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.