Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 606 Bytes

filter.md

File metadata and controls

23 lines (18 loc) · 606 Bytes

Filter 筛选器

Example

$filter = \Lego::filter(new Blog);
$filter->addText('title', 'Title');
$filter->addDaterange('created_at', 'Created At');

Query Scope

$filter->addSelect('custom')->values('hot', 'normal')
	->scope('hotOrNormal') // Laravel Query Scope, call `Blog::scopeHotOrNormal($query, $value)`
	// 注意下面的第一个参数为 Lego 中内置的 Query 接口类,并非 Laravel 中的 QueryBuilder
	->scope(function (Query $query, $value) {
	    return $value === 'hot'
	        ? $query->whereGt('pv', 1000)
	        : $query->whereLte('pv', 1000)
	})