diff --git a/backend/app/Http/Controllers/Api/MeetingsController.php b/backend/app/Http/Controllers/Api/MeetingsController.php index 73e018a3..db37c7da 100644 --- a/backend/app/Http/Controllers/Api/MeetingsController.php +++ b/backend/app/Http/Controllers/Api/MeetingsController.php @@ -18,6 +18,7 @@ use App\Models\Father; use App\Models\FatherRelation; use App\Mail\FathersApprovalMail; +use App\Mail\MeetingEditNotification; class MeetingsController extends Controller { public function register (Request $r) { @@ -800,12 +801,36 @@ class MeetingsController extends Controller { } // データベースに保存します。 - Meeting::where('id', (int)$meeting_id)->update($update); + DB::beginTransaction(); + + $meeting = Meeting::find((int)$meeting_id); + + $meeting->title = $update['title']; + $meeting->text = $update['text']; + if (isset($update['memo'])) $meeting->memo = $update['memo']; + if (isset($update['pdf'])) $meeting->pdf = $update['pdf']; + + $meeting->save(); + + // 子供達を知らせます。 + if (null !== ($fr = FatherRelation::where('father_id', (int)session()->get('fathers')['id'])->get())) { + foreach ($fr as $f) { + if (null === ($child = Child::where('id', $f->child_id)->first())) { + Log::critical('ミーティングの編集エラー:子供データが存在しません。親ID:'.session()->get('fathers')['id'].'、子ID:'.$f->child_id); + } + else { + Mail::to($child->email)->send(new MeetingEditNotification(session()->get('fathers')['company'], (int)$meeting_id)); + } + } + } + + DB::commit(); } catch (\Throwable $e) { Log::critical($e->getMessage()); if (isset($r->pdf) && !is_null($r->pdf)) { Storage::disk('private')->delete($filename); } + DB::rollback(); return ['status_code' => 400]; }