改进 排序

This commit is contained in:
iVampireSP.com 2023-02-17 15:19:45 +08:00
parent 89d4fe0a69
commit 1817879dff
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
4 changed files with 10 additions and 4 deletions

View File

@ -18,7 +18,7 @@ class MaintenanceController extends Controller
*/
public function index(): View
{
$maintenances = (new Maintenance)->all();
$maintenances = (new Maintenance)->orderByStartAt()->get();
return view('admin.maintenances.index', compact('maintenances'));
}

View File

@ -10,7 +10,7 @@ class MaintenanceController extends Controller
{
public function __invoke(): JsonResponse
{
$maintenances = (new Maintenance)->all();
$maintenances = (new Maintenance)->orderByStartAt()->get();
return $this->success($maintenances);
}

View File

@ -30,6 +30,12 @@ class Maintenance extends Model
'module',
];
// 根据 start_at 排序
public function scopeOrderByStartAt($query)
{
return $query->orderBy('start_at', 'desc');
}
public function module()
{
return $this->belongsTo(Module::class);

View File

@ -27,9 +27,9 @@ public function up(): void
$table->foreign('module_id')->references('id')->on('modules')->onDelete('set null');
// 开始于
$table->dateTime('start_at')->nullable();
$table->dateTime('start_at')->nullable()->index();
$table->dateTime('end_at')->nullable();
$table->dateTime('end_at')->nullable()->index();
});
}