laravel 分页继承\Illuminate\Database\Eloquent\Builder 查考以下代码修改默认分页或者其他骚操作 例如 参数pageSize为999不分页直接获取全部数据
<?php
namespace App\Models;
use App\Observers\BaseObserver;
use ReflectionClass;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class BaseModel extends Model
{
protected $table;
protected $casts = [];
public function newEloquentBuilder($query)
{
return new Builder($query);
}
}
class Builder extends \Illuminate\Database\Eloquent\Builder
{
public function paginate($perPage = null, $columns = ['*'], $pageName = 'pageNo', $page = null)
{
if (request('pageSize') == 999) {
return parent::get($columns);
} else {
$perPage = $perPage ? $perPage : request('pageSize', 15);
return parent::paginate($perPage, $columns, $pageName, $page);
}
}
}
|