PHP code example of luffluo / laravel-orm-support

1. Go to this page and download the library: Download luffluo/laravel-orm-support 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/ */

    

luffluo / laravel-orm-support example snippets




declare(strict_types = 1);

namespace Illuminate\Database\Query;

class Builder
{
    /**
    * Get the current query value bindings in a flattened array.
    *
    * @return array
    */
    public function getBindings()
    {
        $bindings = Arr::flatten($this->bindings);
        
        if ($this->unions && count($this->bindings['union']) <= 0) {
            foreach ($this->unions as $union) {
                $bindings = array_merge($bindings, $union['query']->getBindings());
            }
        }
        
        return $bindings;
    }
}

use \Luffluo\LaravelOrmSupport\Traits\MonthlyScale;

class Model
{
    use MonthlyScale;
}

Model::query()->count();

// 上周
Model::queryForLastWeek()->count();

// 上上周
Model::queryForLastWeeks(2)->count();

Model::queryForPeriod('2019-01', '2019-11')->count();

Model::queryForYearMonth('201901')->count();

Model::queryForPeriod('2019-11-26', '2020-11-26')
    ->unionSelect('xxx', 'xxx')
    ->unionSelectRaw('xxx', 'xxx')
    ->count();

Model::queryForPeriod('2019-11-26', '2020-11-26')
    ->unionWhere('xxx', 'xxx')
    ->unionOrWhere('xxx', 'xxx')
    ->unionWhereIn('xxx', ['xx', 'xx'])
    ->unionWhereBetween('xx', ['xxx', 'xxx'])
    ->count();

Model::queryForPeriod('2019-11-26', '2020-11-26')
    ->unionGroupBy('xxx', 'xxx')
    ->count();
json
{
    "autoload": {
        "files": [
            "replaces/Database/Query/Builder.php",
        ]
    }
}