Updated VolumController.php

This commit is contained in:
m.razaghi
2026-08-18 14:04:54 +03:30
parent b1c5345d22
commit 4c6eb52716

View File

@@ -57,8 +57,8 @@ class VolumController extends Controller
$gate_id = $request->gate_id; $gate_id = $request->gate_id;
$perPage = $request->per_page ?? 10; $perPage = $request->per_page ?? 10;
if ($bookId) { if ($bookId) {
// ترتیب درست اعمال شد
$book = Book::with(['divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art']) $book = Book::with(['divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])
->find($bookId); ->find($bookId);
@@ -96,7 +96,7 @@ class VolumController extends Controller
} }
if ($division_id) { if ($division_id) {
$division = Division::with(['sections', 'chapters', 'parts', 'gates', 'branchs', 'art']) $division = Division::with(['sections', 'chapters', 'parts', 'gate', 'branch', 'art'])
->find($division_id); ->find($division_id);
if (! $division) { if (! $division) {
@@ -105,7 +105,7 @@ class VolumController extends Controller
$data = []; $data = [];
$foundRelation = false; $foundRelation = false;
foreach (['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'] as $relation) { foreach (['sections', 'chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
if ($division->{$relation}->count() > 0) { if ($division->{$relation}->count() > 0) {
$foundRelation = true; $foundRelation = true;
$items = $division->{$relation}()->paginate($perPage); $items = $division->{$relation}()->paginate($perPage);
@@ -130,7 +130,7 @@ class VolumController extends Controller
} }
if ($section_id) { if ($section_id) {
$section = Section::with(['chapters', 'parts', 'gates', 'branchs', 'art']) $section = Section::with(['chapters', 'parts', 'gate', 'branch', 'art'])
->find($section_id); ->find($section_id);
if (! $section) { if (! $section) {
@@ -139,7 +139,7 @@ class VolumController extends Controller
$data = []; $data = [];
$foundRelation = false; $foundRelation = false;
foreach (['chapters', 'parts', 'gates', 'branchs', 'art'] as $relation) { foreach (['chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
if ($section->{$relation}->count() > 0) { if ($section->{$relation}->count() > 0) {
$foundRelation = true; $foundRelation = true;
$items = $section->{$relation}()->paginate($perPage); $items = $section->{$relation}()->paginate($perPage);
@@ -197,7 +197,7 @@ class VolumController extends Controller
} }
if ($chapter_id) { if ($chapter_id) {
$chapter = Chapter::with(['parts', 'gates', 'branchs', 'art']) $chapter = Chapter::with(['parts', 'gate', 'branch', 'art'])
->find($chapter_id); ->find($chapter_id);
if (! $chapter) { if (! $chapter) {
@@ -206,7 +206,7 @@ class VolumController extends Controller
$data = []; $data = [];
$foundRelation = false; $foundRelation = false;
foreach (['parts', 'gates', 'branchs', 'art'] as $relation) { foreach (['parts', 'gate', 'branch', 'art'] as $relation) {
if ($chapter->{$relation}->count() > 0) { if ($chapter->{$relation}->count() > 0) {
$foundRelation = true; $foundRelation = true;
$items = $chapter->{$relation}()->paginate($perPage); $items = $chapter->{$relation}()->paginate($perPage);
@@ -231,7 +231,7 @@ class VolumController extends Controller
} }
if ($part_id) { if ($part_id) {
$part = Part::with(['gates', 'branchs', 'art']) $part = Part::with(['gate', 'branch', 'art'])
->find($part_id); ->find($part_id);
if (! $part) { if (! $part) {
@@ -240,7 +240,7 @@ class VolumController extends Controller
$data = []; $data = [];
$foundRelation = false; $foundRelation = false;
foreach (['gates', 'branchs', 'art'] as $relation) { foreach (['gate', 'branch', 'art'] as $relation) {
if ($part->{$relation}->count() > 0) { if ($part->{$relation}->count() > 0) {
$foundRelation = true; $foundRelation = true;
$items = $part->{$relation}()->paginate($perPage); $items = $part->{$relation}()->paginate($perPage);
@@ -265,7 +265,7 @@ class VolumController extends Controller
} }
if ($gate_id) { if ($gate_id) {
$gate = Gate::with(['branchs', 'art']) $gate = Gate::with(['branch', 'art'])
->find($gate_id); ->find($gate_id);
if (! $gate) { if (! $gate) {
@@ -274,7 +274,7 @@ class VolumController extends Controller
$data = []; $data = [];
$foundRelation = false; $foundRelation = false;
foreach (['branchs', 'art'] as $relation) { foreach (['branch', 'art'] as $relation) {
if ($gate->{$relation}->count() > 0) { if ($gate->{$relation}->count() > 0) {
$foundRelation = true; $foundRelation = true;
$items = $gate->{$relation}()->paginate($perPage); $items = $gate->{$relation}()->paginate($perPage);
@@ -550,7 +550,7 @@ class VolumController extends Controller
return $this->success([], 'Law not found'); return $this->success([], 'Law not found');
} }
$data = $this->checkRelations($law, ['volums', 'book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'arts'], $perPage); $data = $this->checkRelations($law, ['volums', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'arts'], $perPage);
if ($data) { if ($data) {
return $this->success($data, 'Success'); return $this->success($data, 'Success');
} }
@@ -587,12 +587,12 @@ class VolumController extends Controller
} }
if ($divisionId) { if ($divisionId) {
$division = Division::with(['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])->find($divisionId); $division = Division::with(['chapters', 'parts', 'gates', 'branchs', 'art'])->find($divisionId);
if (! $division) { if (! $division) {
return $this->success([], 'Division not found'); return $this->success([], 'Division not found');
} }
$data = $this->checkRelations($division, ['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'], $perPage); $data = $this->checkRelations($division, ['chapters', 'parts', 'gates', 'branchs', 'art'], $perPage);
if ($data) { if ($data) {
return $this->success($data, 'Success'); return $this->success($data, 'Success');
} }
@@ -615,12 +615,12 @@ class VolumController extends Controller
} }
if ($chapterId) { if ($chapterId) {
$chapter = Chapter::with(['parts', 'gates', 'branchs', 'art'])->find($chapterId); $chapter = Chapter::with(['parts', 'gate', 'art'])->find($chapterId);
if (! $chapter) { if (! $chapter) {
return $this->success([], 'Chapter not found'); return $this->success([], 'Chapter not found');
} }
$data = $this->checkRelations($chapter, ['parts', 'gates', 'branchs', 'art'], $perPage); $data = $this->checkRelations($chapter, ['parts', 'gate', 'art'], $perPage);
if ($data) { if ($data) {
return $this->success($data, 'Success'); return $this->success($data, 'Success');
} }
@@ -629,12 +629,12 @@ class VolumController extends Controller
} }
if ($partId) { if ($partId) {
$part = Part::with(['gates', 'branchs', 'art'])->find($partId); $part = Part::with(['gates', 'art'])->find($partId);
if (! $part) { if (! $part) {
return $this->success([], 'Part not found'); return $this->success([], 'Part not found');
} }
$data = $this->checkRelations($part, ['gates', 'branchs', 'art'], $perPage); $data = $this->checkRelations($part, ['gates', 'art'], $perPage);
if ($data) { if ($data) {
return $this->success($data, 'Success'); return $this->success($data, 'Success');
} }
@@ -643,12 +643,12 @@ class VolumController extends Controller
} }
if ($gateId) { if ($gateId) {
$gate = Gate::with(['branchs', 'art'])->find($gateId); $gate = Gate::with(['art'])->find($gateId);
if (! $gate) { if (! $gate) {
return $this->success([], 'Gate not found'); return $this->success([], 'Gate not found');
} }
$data = $this->checkRelations($gate, ['branchs', 'art'], $perPage); $data = $this->checkRelations($gate, ['art'], $perPage);
if ($data) { if ($data) {
return $this->success($data, 'Success'); return $this->success($data, 'Success');
} }
@@ -657,12 +657,12 @@ class VolumController extends Controller
} }
if ($branchId) { if ($branchId) {
$branch = Branch::with(['art'])->find($branchId); $branch = Branch::with(['chapters', 'gates', 'art'])->find($branchId);
if (! $branch) { if (! $branch) {
return $this->success([], 'Branch not found'); return $this->success([], 'Branch not found');
} }
$data = $this->checkRelations($branch, ['art'], $perPage); $data = $this->checkRelations($branch, ['chapters', 'gates', 'art'], $perPage);
if ($data) { if ($data) {
return $this->success($data, 'Success'); return $this->success($data, 'Success');
} }