This commit is contained in:
F4ilji
2026-04-07 17:54:26 +05:00
parent 04adba6682
commit 936b1fb5b0
468 changed files with 43498 additions and 4176 deletions
@@ -0,0 +1,45 @@
<?php
namespace App\Containers\Dashboard\Actions\SubSections;
use App\Containers\AppStructure\Models\Page;
use App\Containers\AppStructure\Models\SubSection;
class UpdateSubSectionAction
{
public function run(SubSection $subSection, array $data): SubSection
{
$subSection->update([
'title' => $data['title'],
'slug' => $data['slug'],
]);
if (isset($data['page_ids'])) {
$this->syncPages($subSection, $data['page_ids']);
}
return $subSection->fresh();
}
private function syncPages(SubSection $subSection, array $pageIds): void
{
Page::query()->where('sub_section_id', '=', $subSection->id)->update(['sub_section_id' => null]);
Page::whereIn('id', $pageIds)->update(['sub_section_id' => $subSection->id]);
$pages = Page::where('is_url', '=', false)
->where('sub_section_id', '=', $subSection->id)
->get();
if ($pages->isEmpty() || !$subSection->mainSection) {
return;
}
$mainSectionSlug = $pages->first()->section->mainSection->slug;
foreach ($pages as $page) {
if ($page->is_registered != true) {
$page->update(['path' => $mainSectionSlug . '/' . $subSection->slug . '/' . $page->slug]);
}
}
}
}