meeting_id)) { return ['status' => 400]; } foreach ($r->all() as $i) { $validate = Validator::make($i, ['image' => 'file|max:1024|mimes:jpg,png,gif']); } $validate->after(function ($validate) { if (count($r->image) > 10) { $validate->errors()->add('count', '10枚以上登録できません。'); } }); if ($validate->fails()) { return ['status_code' => 422, 'error_messages' => $validate->errors()]; } $insert = ['meeting_id' => $meeting_id, 'image' => $image]; foreach ($r->images as $image) { try { MeetingImage::create($insert); } catch (\Throwable $e) { // 失敗 Log::critical($e->getMessage()); return ['status_code' => 400]; } } return ['status_code' => 200]; } public function delete ($meeting_id) { if (!isset($meeting_id)) { return ['status_code' => 400]; } if (null === ($get = MeetingImage::select('image')->where('meeting_id', $meeting_id)->get())) { return ['status_code' => 400]; } try { MeetingImage::where('meeting_id', $meeting_id)->delete(); foreach ($get as $g) { Storage::disk('public')->delete($g->image); } } catch (\Throwable $e) { // 失敗 Log::critical($e->getMessage()); return ['status_code' => 400]; } return ['status_code' => 200]; } }