Updated client contract table and notification table, multiselect
This commit is contained in:
@@ -13,8 +13,10 @@ class ActivityNotificationController extends Controller
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'activity_id' => ['required', 'integer', 'exists:activities,id'],
|
||||
$data = $request->validate([
|
||||
'activity_id' => ['sometimes', 'integer', 'exists:activities,id'],
|
||||
'activity_ids' => ['sometimes', 'array', 'min:1'],
|
||||
'activity_ids.*' => ['integer', 'exists:activities,id'],
|
||||
]);
|
||||
|
||||
$userId = optional($request->user())->id;
|
||||
@@ -22,19 +24,29 @@ public function __invoke(Request $request)
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$activity = Activity::query()->select(['id', 'due_date'])->findOrFail($request->integer('activity_id'));
|
||||
$due = optional($activity->due_date) ? date('Y-m-d', strtotime($activity->due_date)) : now()->toDateString();
|
||||
$ids = [];
|
||||
if (!empty($data['activity_id'])) {
|
||||
$ids[] = $data['activity_id'];
|
||||
}
|
||||
if (!empty($data['activity_ids'])) {
|
||||
$ids = array_merge($ids, $data['activity_ids']);
|
||||
}
|
||||
$ids = array_unique($ids);
|
||||
|
||||
ActivityNotificationRead::query()->updateOrCreate(
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'activity_id' => $activity->id,
|
||||
'due_date' => $due,
|
||||
],
|
||||
[
|
||||
'read_at' => now(),
|
||||
]
|
||||
);
|
||||
$activities = Activity::query()->select(['id', 'due_date'])->whereIn('id', $ids)->get();
|
||||
foreach ($activities as $activity) {
|
||||
$due = optional($activity->due_date) ? date('Y-m-d', strtotime($activity->due_date)) : now()->toDateString();
|
||||
ActivityNotificationRead::query()->updateOrCreate(
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'activity_id' => $activity->id,
|
||||
'due_date' => $due,
|
||||
],
|
||||
[
|
||||
'read_at' => now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user