親を削除したら、子リレーション、会議、会議のPDF、会議の画像データ及び、会議の画像ファイルも削除
このコミットが含まれているのは:
コミット
bbf43d3ed8
|
@ -16,6 +16,8 @@ use Image;
|
|||
use App\Models\Father;
|
||||
use App\Models\FatherRelation;
|
||||
use App\Models\EmailActivation;
|
||||
use App\Models\Meeting;
|
||||
use App\Models\MeetingImage;
|
||||
use App\Models\MeetingApprovals;
|
||||
|
||||
use App\Mail\FathersForgetPasswordMail;
|
||||
|
@ -517,13 +519,38 @@ class FathersController extends Controller {
|
|||
}
|
||||
|
||||
public function withdrawal (Request $r) {
|
||||
$images = [];
|
||||
$pdfs = [];
|
||||
|
||||
try {
|
||||
// DBに入ります。
|
||||
DB::beginTransaction();
|
||||
|
||||
$father = Father::find((int)$r->father_id);
|
||||
$rel = FatherRelation::where('father_id', (int)$r->father_id);
|
||||
$meet = Meeting::where('father_id', (int)$r->father_id);
|
||||
|
||||
if ($meet->count() > 0) {
|
||||
foreach ($meet->get() as $n) {
|
||||
$meim = MeetingImage::where('meeting_id', (int)$n->id);
|
||||
$oldpdf = str_replace('/files/', '', $n->pdf);
|
||||
$pdfs[] = $oldpdf;
|
||||
|
||||
if ($meim->count() > 0) {
|
||||
foreach ($meim->get() as $m) {
|
||||
$oldimg = str_replace('/files/', '', $m->image);
|
||||
$images[] = $oldimg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$img = $father->image;
|
||||
|
||||
$father->delete();
|
||||
$rel->delete();
|
||||
$meet->delete();
|
||||
$meim->delete();
|
||||
|
||||
if (!is_null($img)) {
|
||||
$img = str_replace('/files/', '', $father->image);
|
||||
|
@ -535,39 +562,29 @@ class FathersController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Session::forget($this->getGuard());
|
||||
DB::commit();
|
||||
} catch (\Throwable $e) {
|
||||
// 失敗
|
||||
Log::critical($e->getMessage());
|
||||
DB::rollback();
|
||||
return ['status_code' => 400, 'error_messages' => ['親の削除に失敗しました。']];
|
||||
}
|
||||
|
||||
// 成功
|
||||
return ['status_code' => 200, 'success_messages' => ['親の削除に成功しました。']];
|
||||
}
|
||||
|
||||
public function delete ($father_id) {
|
||||
try {
|
||||
// DBに入ります。
|
||||
DB::beginTransaction();
|
||||
|
||||
$father = Father::find((int)$father_id);
|
||||
$img = $father->image;
|
||||
$father->delete();
|
||||
|
||||
if (!is_null($img)) {
|
||||
$img = str_replace('/files/', '', $father->image);
|
||||
if (!Storage::disk('private')->exists($img)) {
|
||||
Log::warning($img.'というパスは不正です。');
|
||||
}
|
||||
else {
|
||||
Storage::disk('private')->delete($img);
|
||||
if (!empty($pdfs)) {
|
||||
foreach ($pdfs as $p) {
|
||||
if (!Storage::disk('private')->exists($p)) {
|
||||
Log::warning($p.'というパスは不正です。');
|
||||
}
|
||||
else {
|
||||
Storage::disk('private')->delete($p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Session::forget($this->getGuard());
|
||||
if (!empty($images)) {
|
||||
foreach ($images as $g) {
|
||||
if (!Storage::disk('private')->exists($g)) {
|
||||
Log::warning($g.'というパスは不正です。');
|
||||
}
|
||||
else {
|
||||
Storage::disk('private')->delete($g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Session::forget('fathers');
|
||||
DB::commit();
|
||||
} catch (\Throwable $e) {
|
||||
// 失敗
|
||||
|
|
新しいイシューから参照