You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
424 B
19 lines
424 B
<?php
|
|
|
|
namespace App\Models;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class BaseModel extends Model
|
|
{
|
|
use HasDateTimeFormatter;
|
|
|
|
//默认按id desc排序
|
|
protected static function booted()
|
|
{
|
|
static::addGlobalScope('orderById', function (Builder $builder) {
|
|
$builder->orderBy((new static())->getTable().'.id', 'desc');
|
|
});
|
|
}
|
|
}
|