storage url o'zgartirildi
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user