Bổ sung sort theo ngày mới nhất

This commit is contained in:
Truong Vo 2024-09-24 16:23:16 +07:00
parent c0826f814e
commit 9e83615eeb
1 changed files with 2 additions and 5 deletions

View File

@ -119,6 +119,7 @@ class TechnicalController extends Controller
->where('user_id', $userId) ->where('user_id', $userId)
->where('point', '>', 0) ->where('point', '>', 0)
->orderBy('point', 'desc') ->orderBy('point', 'desc')
->orderBy('updated_at', 'desc')
->get(); ->get();
if ($technicals->isEmpty()) { if ($technicals->isEmpty()) {
return []; return [];
@ -221,14 +222,10 @@ class TechnicalController extends Controller
'technicals.*.point' => 'required|integer|min:0|max:3', // Điểm trong khoảng [0-3] 'technicals.*.point' => 'required|integer|min:0|max:3', // Điểm trong khoảng [0-3]
]); ]);
// Lấy danh sách technicals của user từ bảng TechnicalUser
$existingTechnicals = TechnicalUser::where('user_id', $userInfo->id)->get()->keyBy('technical_id'); $existingTechnicals = TechnicalUser::where('user_id', $userInfo->id)->get()->keyBy('technical_id');
foreach ($validatedData['technicals'] as $technical) { foreach ($validatedData['technicals'] as $technical) {
$existingTechnical = $existingTechnicals->get($technical['technical_id']); $existingTechnical = $existingTechnicals->get($technical['technical_id']);
// if ($technical['technical_id'] == 7) {
// dd($existingTechnical,$userInfo);
// }
if ($existingTechnical) { if ($existingTechnical) {
// Nếu technical_id đã tồn tại và point khác, thì update // Nếu technical_id đã tồn tại và point khác, thì update
if ($existingTechnical->point !== $technical['point']) { if ($existingTechnical->point !== $technical['point']) {