2021-09-30 13:33:23 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-09-30 13:33:23 +09:00
|
|
|
|
|
|
|
use App\Models\MeetingImage;
|
|
|
|
|
|
|
|
class MeetingImagesController extends Controller {
|
2021-10-01 14:22:07 +09:00
|
|
|
public function register (Request $r) {
|
2021-10-06 14:50:13 +09:00
|
|
|
if (!isset($r->meeting_id)) {
|
|
|
|
return ['status' => 400];
|
|
|
|
}
|
|
|
|
|
2021-10-01 14:22:07 +09:00
|
|
|
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()];
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
$insert = ['meeting_id' => $meeting_id, 'image' => $image];
|
2021-10-01 14:22:07 +09:00
|
|
|
|
|
|
|
foreach ($r->images as $image) {
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
|
|
|
MeetingImage::create($insert);
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-10-01 14:22:07 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ['status_code' => 200];
|
2021-10-01 12:51:56 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:22:07 +09:00
|
|
|
public function deleteRelationMeeting ($meeting_id) {
|
2021-10-07 13:51:53 +09:00
|
|
|
try {
|
|
|
|
MeetingImage::where('meeting_id', $meeting_id)->delete();
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400];
|
2021-10-01 14:22:07 +09:00
|
|
|
}
|
2021-10-01 12:51:56 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200];
|
2021-10-01 12:51:56 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|