PHP code example of linron / hyperf-filter

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

    

linron / hyperf-filter example snippets

bash

declare(strict_types=1);

namespace App\Filter;
use Hyperf\Filter\QueryFilter;
use Hyperf\Database\Model\Builder;

class TenderListFilter extends QueryFilter
{
    public function projectId(int $projectId): Builder
    {
        return $this->builder->where('project_id', $projectId);
    }

    public function partyName(string $partyName): Builder
    {
        return $this->builder->whereHas('project.partyUnit', function (Builder $query) use ($partyName) {
            $query->where('name', 'like', "%$partyName%");
        });
    }

    public function humanCost(array $humanCost): Builder
    {
        [$start, $end] = $humanCost;
        if($start) $this->builder->where('human_cost', '>=', $start);
        if($end) $this->builder->where('human_cost', '<=', $end);
        return $this->builder;
    }

    public function masterCost(array $masterCost): Builder
    {
        [$start, $end] = $masterCost;
        if($start) $this->builder->where('master_cost', '>=', $start);
        if($end) $this->builder->where('master_cost', '<=', $end);
        return $this->builder;
    }

    public function slaveCost(array $slaveCost): Builder
    {
        [$start, $end] = $slaveCost;
        if($start) $this->builder->where('slave_cost', '>=', $start);
        if($end) $this->builder->where('slave_cost', '<=', $end);
        return $this->builder;
    }

    public function deviceCost(array $deviceCost): Builder
    {
        [$start, $end] = $deviceCost;
        if($start) $this->builder->where('device_cost', '>=', $start);
        if($end) $this->builder->where('device_cost', '<=', $end);
        return $this->builder;
    }

    public function totalCost(array $totalCost): Builder
    {
        [$start, $end] = $totalCost;
        if($start) $this->builder->where('total_cost', '>=', $start);
        if($end) $this->builder->where('total_cost', '<=', $end);
        return $this->builder;
    }

    public function status(int $status): Builder
    {
        return $this->builder->where('status', $status);
    }
}