diff --git a/backend/app/Http/Controllers/Api/MeetingsController.php b/backend/app/Http/Controllers/Api/MeetingsController.php index 3f9fbb80..a44d6b54 100644 --- a/backend/app/Http/Controllers/Api/MeetingsController.php +++ b/backend/app/Http/Controllers/Api/MeetingsController.php @@ -501,6 +501,16 @@ class MeetingsController extends Controller { 'memo' => 'nullable|max:2000', ]); + // ミームタイプ + Validator::extend('pdf_meme', function ($attribute, $value, $params, $validator) { + try { + return mime_content_type($value) == 'application/pdf'; + } catch (\Throwable $e) { + Log::critical($e->getMessage()); + return false; + } + }); + if ($validate->fails()) { return ['status_code' => 422, 'error_messages' => $validate->errors()]; } @@ -517,6 +527,13 @@ class MeetingsController extends Controller { $filename = uniqid() . '.pdf'; $pdf = base64_decode(substr($r->pdf, strpos($r->pdf, ',') + 1)); $update['pdf'] = '/storage/'.$filename; + + if ($chk = Meeting::select('pdf')->where('id', (int)$meeting_id)->first()) { + if (Storage::disk('public')->has($chk->pdf)) { + Storage::disk('public')->delete($chk->pdf); + } + } + Storage::disk('public')->put($filename, $pdf); } diff --git a/backend/resources/lang/ja/validation.php b/backend/resources/lang/ja/validation.php index 959159db..ed8043a1 100644 --- a/backend/resources/lang/ja/validation.php +++ b/backend/resources/lang/ja/validation.php @@ -106,6 +106,7 @@ return [ 'required_with_all' => 'The :attribute field is required when :values are present.', 'required_without' => 'The :attribute field is required when :values is not present.', 'required_without_all' => 'The :attribute field is required when none of :values are present.', + 'pdf_meme' => 'ファイル形式はpdfのみです。', 'prohibited' => 'The :attribute field is prohibited.', 'prohibited_if' => 'The :attribute field is prohibited when :other is :value.', 'prohibited_unless' => 'The :attribute field is prohibited unless :other is in :values.',