改进 排序
This commit is contained in:
parent
89d4fe0a69
commit
1817879dff
@ -18,7 +18,7 @@ class MaintenanceController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(): View
|
public function index(): View
|
||||||
{
|
{
|
||||||
$maintenances = (new Maintenance)->all();
|
$maintenances = (new Maintenance)->orderByStartAt()->get();
|
||||||
|
|
||||||
return view('admin.maintenances.index', compact('maintenances'));
|
return view('admin.maintenances.index', compact('maintenances'));
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ class MaintenanceController extends Controller
|
|||||||
{
|
{
|
||||||
public function __invoke(): JsonResponse
|
public function __invoke(): JsonResponse
|
||||||
{
|
{
|
||||||
$maintenances = (new Maintenance)->all();
|
$maintenances = (new Maintenance)->orderByStartAt()->get();
|
||||||
|
|
||||||
return $this->success($maintenances);
|
return $this->success($maintenances);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,12 @@ class Maintenance extends Model
|
|||||||
'module',
|
'module',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 根据 start_at 排序
|
||||||
|
public function scopeOrderByStartAt($query)
|
||||||
|
{
|
||||||
|
return $query->orderBy('start_at', 'desc');
|
||||||
|
}
|
||||||
|
|
||||||
public function module()
|
public function module()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Module::class);
|
return $this->belongsTo(Module::class);
|
||||||
|
@ -27,9 +27,9 @@ public function up(): void
|
|||||||
$table->foreign('module_id')->references('id')->on('modules')->onDelete('set null');
|
$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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user