mitirrli/build-query

model query for orm.

1.2.0 2021-03-25 07:33 UTC

This package is auto-updated.

Last update: 2024-11-17 14:05:19 UTC


README

🌈 use for build query.

Build Status Coverage Status Codacy Badge Better Code Total Downloads GitHub (pre-)release

Environment

  • PHP >= 7.1

Installation

$ composer require mitirrli/build-query

QuickStart

  1. Common filter
use Mitirrli\Buildable\Constant;
use Mitirrli\Buildable\Buildable;

$this->param($params ?? [])
    ->initial(['initial' => 0])
    ->key('avatar')
    ->key('name', Constant::RIGHT)
    ->key('name', Constant::ALL)
    ->inKey('type')
    ->betweenKey('created_at', ['start' => 'create', 'end' => 'end'])
    ->beforeKey('id')
    ->afterKey('id')
    ->unsetKey('initial')
    ->sort('created_at')
    ->result();
  1. Get order
use Mitirrli\Buildable\Buildable;

$order = $this
   ->param(array_merge(['update_time' => 'desc'], $params)) //默认更新时间排序
   ->sort(['update_time', 'a.update_time']) //更新时间
   ->sort(['id', 'a.id']) //ID
   ->sort('create_time')
   ->order();