PHP code example of missing-u / http-filter
1. Go to this page and download the library: Download missing-u/http-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/ */
missing-u / http-filter example snippets
$pass_params = request()->all();
$where = [];
if (isset($pass_params[ 'mobile' ])) {
$where[ 'mobile' ] = [
'mobile','like',$pass_params['mobile']
];
}
if (isset($pass_params[ 'idcard' ])) {
$where[ 'idcard' ] = [
'idcard','like',$pass_params['idcard']
];
}
if (isset($pass_params[ 'from' ])) {
$where[ 'from' ] = [
'created_time','>=',$pass_params['from']
];
}
if (isset($pass_params[ 'to' ])) {
$where[ 'to' ] = [
'created_time','>=',$pass_params['to']
];
}
Person::where(
$where
);
class PersonIndexFilter extends \HttpFilter\Filter
{
use \HttpFilter\IsolatedFilter\TimePeriod;
public function __construct($request)
{
parent::__construct($request);
//如果 字段是 created_at
//那么就不用调用下面这里
//哪这个举个例子
$this->setTimeColumnName('create_time');
}
public function mobile(int $mobile)
{
$this->builder->where(
'mobile', 'like', $mobile
);
}
public function idcard(string $idcard)
{
$this->builder->where(
'idcard', 'like', $idcard
);
}
}
$filter = new PersonIndexFilter(request());
Person::addGlobalScope($filter);
TpShopInfo::first();