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
|
||||
|
||||
@@ -45,23 +45,22 @@ class Controller extends ExController
|
||||
return view('dashboard.compilations.index', compact('compilations'));
|
||||
}
|
||||
|
||||
// public function store(StoreRequest $request)
|
||||
// {
|
||||
// if ($request->isMethod('get')) {
|
||||
// $this->authorize('create', 'compilations');
|
||||
//
|
||||
//// $this->authorize('content-manager');
|
||||
// $categories = $this->categories->where('parent_id', null)->get();
|
||||
// return view('dashboard.compilations.store', compact('categories'));
|
||||
// }
|
||||
//
|
||||
// $this->dispatchSync(new StoreJob($request));
|
||||
//
|
||||
// $this->success(trans('admin.messages.created'));
|
||||
// return response()->json([
|
||||
// 'status' => true
|
||||
// ]);
|
||||
// }
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
if ($request->isMethod('get')) {
|
||||
$this->authorize('create', 'compilations');
|
||||
|
||||
$categories = $this->categories->whereNull('parent_id')->orderBy('position')->get();
|
||||
return view('dashboard.compilations.store', compact('categories'));
|
||||
}
|
||||
|
||||
$this->dispatchSync(new StoreJob($request));
|
||||
|
||||
$this->success(trans('admin.messages.created'));
|
||||
return response()->json([
|
||||
'status' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Compilation $compilation
|
||||
@@ -74,17 +73,20 @@ class Controller extends ExController
|
||||
if ($request->isMethod('get')) {
|
||||
// $this->authorize('content-manager');
|
||||
|
||||
$compilation->loadMissing(['products:id,name,poster']);
|
||||
|
||||
$this->authorize('update', 'compilations');
|
||||
|
||||
foreach ($compilation->products as $product) {
|
||||
$product->poster = '/'. $product->poster;
|
||||
$products = $compilation->dashboardProducts()
|
||||
->select('products.id', 'products.name', 'products.poster')
|
||||
->get();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$product->poster = $product->getPoster();
|
||||
$product->name = $product->name['ru'];
|
||||
}
|
||||
|
||||
$compilation->setRelation('products', $products);
|
||||
|
||||
$categories = $this->categories->where('parent_id', false)->get();
|
||||
$categories = $this->categories->whereNull('parent_id')->orderBy('position')->get();
|
||||
|
||||
|
||||
return view('dashboard.compilations.update', compact('compilation', 'categories'));
|
||||
@@ -104,12 +106,34 @@ class Controller extends ExController
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$query = $request->name;
|
||||
$query = trim((string) $request->name);
|
||||
$categoryId = (int) $request->get('category_id');
|
||||
|
||||
$product = $this->products->published()->where('name->ru', 'like', $query . '%')->get()->map(function ($product) {
|
||||
$product = $this->products
|
||||
->newQuery()
|
||||
->whereNull('child_id')
|
||||
->when($categoryId > 0, function ($builder) use ($categoryId) {
|
||||
$categoryIds = $this->categoryIdsWithChildren($categoryId);
|
||||
|
||||
$builder->whereHas('categories', function ($category) use ($categoryIds) {
|
||||
$category->whereIn('categories.id', $categoryIds);
|
||||
});
|
||||
})
|
||||
->when($query !== '', function ($builder) use ($query) {
|
||||
$builder->where(function ($search) use ($query) {
|
||||
$search
|
||||
->where('name->ru', 'like', '%' . $query . '%')
|
||||
->orWhere('name->uz', 'like', '%' . $query . '%')
|
||||
->orWhere('article_number', 'like', '%' . $query . '%');
|
||||
});
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->limit(30)
|
||||
->get()
|
||||
->map(function ($product) {
|
||||
return [
|
||||
'id' => $product->id,
|
||||
'poster' => '/' . $product->poster,
|
||||
'poster' => $product->getPoster(),
|
||||
'name' => $product->name['ru']
|
||||
];
|
||||
});
|
||||
@@ -120,6 +144,27 @@ class Controller extends ExController
|
||||
]);
|
||||
}
|
||||
|
||||
private function categoryIdsWithChildren(int $categoryId): array
|
||||
{
|
||||
$category = Category::with('children.children')->find($categoryId);
|
||||
|
||||
if (!$category) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ids = [$category->id];
|
||||
|
||||
foreach ($category->children as $child) {
|
||||
$ids[] = $child->id;
|
||||
|
||||
foreach ($child->children as $grandChild) {
|
||||
$ids[] = $grandChild->id;
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Compilation $compilation
|
||||
|
||||
@@ -283,11 +283,7 @@ class Controller extends ExController
|
||||
foreach ($product->childrens as $children) {
|
||||
foreach ($children->screens as $screen) {
|
||||
$screen->sizeText = $screen->size / 1024 . 'Kb';
|
||||
if (env('FILESYSTEM_DISK') == 's3') {
|
||||
$screen->url = Storage::url($screen->path);
|
||||
} else {
|
||||
$screen->url = '/' . $screen->path;
|
||||
}
|
||||
$screen->url = Storage::url($screen->path);
|
||||
$screen->type = "image/jpeg";
|
||||
}
|
||||
}
|
||||
@@ -318,15 +314,15 @@ class Controller extends ExController
|
||||
try {
|
||||
$this->dispatchSync(new UpdateJob($product, $request));
|
||||
$this->dispatchSync(new ChildUpdateJob($request, $product));
|
||||
$this->charSync($product, $request->characteristics);
|
||||
$this->dispatchSync(new DeletesJob($request));
|
||||
} catch (Exception $e) {
|
||||
return Response::json([
|
||||
"messages" => $e->getMessage()
|
||||
]);
|
||||
'status' => false,
|
||||
'messages' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
$this->charSync($product, $request->characteristics);
|
||||
|
||||
$this->dispatchSync(new DeletesJob($request));
|
||||
$this->info(trans('admin.messages.updated'));
|
||||
|
||||
return response()->json([
|
||||
@@ -394,8 +390,12 @@ class Controller extends ExController
|
||||
$article_number = empty($request->get('article_number')) ? null : $request->get('article_number');
|
||||
|
||||
if ($category) {
|
||||
$categoryFind = Category::find($category);
|
||||
list($categoryFind, $category_id) = $this->categoryQuery->getCategoriesAndCategoryMainId($categoryFind);
|
||||
$categoryFind = Category::withTrashed()->find($category);
|
||||
if ($categoryFind) {
|
||||
list($categoryFind, $category_id) = $this->categoryQuery->getCategoriesAndCategoryMainId($categoryFind);
|
||||
} else {
|
||||
$category_id = [];
|
||||
}
|
||||
} else {
|
||||
$category_id = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user