PHP code example of jiaxincui / laravel-request-query

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

    

jiaxincui / laravel-request-query example snippets


// App\Filters\UserFilter

public function onlyVip($arg){
    $this->builder->where('vip', '=', $arg)
}

// App\Filters\UserFilter

// 定义可用于条件查询的列名
protected function getFieldsQueryable(): array {
    return [
        'name',
        'email',
        'userinfo.age' // 关联查询
    ]
}

// 定义可用于关联查询的表
protected function getReleasable(): array {
    return [
        'userinfo',
        'addresses'
    ]
}

// 定义可用于排序的列
protected function getSortable(): array {
    return [
        'id',
        'created_at'
    ]
}

// App\Filters\UserFilter

protected function applyBaseFilter(Builder $builder): Builder
{
    return $builder->where('disabled', 0);
}