storage url o'zgartirildi
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Jobs\Dashboard\Category\Store as StoreJob;
|
||||
use App\Jobs\Dashboard\Category\Update as UpdateJob;
|
||||
use App\Models\Characteristic;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Controller extends ExController
|
||||
@@ -168,29 +169,9 @@ class Controller extends ExController
|
||||
*/
|
||||
public function position_save(Request $request)
|
||||
{
|
||||
foreach ($request->categories as $category) {
|
||||
$cat = Category::find($category['id']);
|
||||
$cat->parent_id = $category['parent_id'] === 'null' ? null : $category['parent_id'];
|
||||
$cat->position = $category['position'];
|
||||
$cat->save();
|
||||
if (!empty($category['children'])) {
|
||||
foreach ($category['children'] as $c) {
|
||||
$cc = Category::find($c['id']);
|
||||
$cc->parent_id = $c['parent_id'] === 'null' ? null : $c['parent_id'];
|
||||
$cc->position = $c['position'];
|
||||
$cc->save();
|
||||
|
||||
if (!empty($c['children'])) {
|
||||
foreach ($c['children'] as $ccc) {
|
||||
$cccc = Category::find($ccc['id']);
|
||||
$cccc->parent_id = $ccc['parent_id'] === 'null' ? null : $ccc['parent_id'];
|
||||
$cccc->position = $ccc['position'];
|
||||
$cccc->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DB::transaction(function () use ($request) {
|
||||
$this->saveCategoryPositions($request->input('categories', []), null);
|
||||
});
|
||||
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
@@ -199,6 +180,34 @@ class Controller extends ExController
|
||||
]);
|
||||
}
|
||||
|
||||
private function saveCategoryPositions(array $categories, $parentId = null): void
|
||||
{
|
||||
foreach (array_values($categories) as $index => $category) {
|
||||
$cat = Category::find($category['id'] ?? null);
|
||||
|
||||
if (!$cat) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cat->parent_id = $this->normalizeParentId($parentId);
|
||||
$cat->position = $index + 1;
|
||||
$cat->save();
|
||||
|
||||
if (!empty($category['children']) && is_array($category['children'])) {
|
||||
$this->saveCategoryPositions($category['children'], $cat->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeParentId($parentId)
|
||||
{
|
||||
if (in_array($parentId, [null, '', 'null', 'NULL', 0, '0'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $parentId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
||||
Reference in New Issue
Block a user