storage url o'zgartirildi

This commit is contained in:
2026-04-28 15:02:06 +05:00
parent 3aa4601229
commit bb733d14c1
37 changed files with 282 additions and 407 deletions

View File

@@ -13,6 +13,7 @@ use App\Jobs\Dashboard\Category\Store as StoreJob;
use App\Jobs\Dashboard\Category\Update as UpdateJob; use App\Jobs\Dashboard\Category\Update as UpdateJob;
use App\Models\Characteristic; use App\Models\Characteristic;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
class Controller extends ExController class Controller extends ExController
@@ -168,29 +169,9 @@ class Controller extends ExController
*/ */
public function position_save(Request $request) public function position_save(Request $request)
{ {
foreach ($request->categories as $category) { DB::transaction(function () use ($request) {
$cat = Category::find($category['id']); $this->saveCategoryPositions($request->input('categories', []), null);
$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();
}
}
}
}
}
$this->info(trans('admin.messages.updated')); $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 * @return array

View File

@@ -45,23 +45,22 @@ class Controller extends ExController
return view('dashboard.compilations.index', compact('compilations')); return view('dashboard.compilations.index', compact('compilations'));
} }
// public function store(StoreRequest $request) public function store(StoreRequest $request)
// { {
// if ($request->isMethod('get')) { if ($request->isMethod('get')) {
// $this->authorize('create', 'compilations'); $this->authorize('create', 'compilations');
//
//// $this->authorize('content-manager'); $categories = $this->categories->whereNull('parent_id')->orderBy('position')->get();
// $categories = $this->categories->where('parent_id', null)->get(); return view('dashboard.compilations.store', compact('categories'));
// return view('dashboard.compilations.store', compact('categories')); }
// }
// $this->dispatchSync(new StoreJob($request));
// $this->dispatchSync(new StoreJob($request));
// $this->success(trans('admin.messages.created'));
// $this->success(trans('admin.messages.created')); return response()->json([
// return response()->json([ 'status' => true
// 'status' => true ]);
// ]); }
// }
/** /**
* @param Compilation $compilation * @param Compilation $compilation
@@ -74,17 +73,20 @@ class Controller extends ExController
if ($request->isMethod('get')) { if ($request->isMethod('get')) {
// $this->authorize('content-manager'); // $this->authorize('content-manager');
$compilation->loadMissing(['products:id,name,poster']);
$this->authorize('update', 'compilations'); $this->authorize('update', 'compilations');
foreach ($compilation->products as $product) { $products = $compilation->dashboardProducts()
$product->poster = '/'. $product->poster; ->select('products.id', 'products.name', 'products.poster')
->get();
foreach ($products as $product) {
$product->poster = $product->getPoster();
$product->name = $product->name['ru']; $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')); return view('dashboard.compilations.update', compact('compilation', 'categories'));
@@ -104,12 +106,34 @@ class Controller extends ExController
*/ */
public function search(Request $request) 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 [ return [
'id' => $product->id, 'id' => $product->id,
'poster' => '/' . $product->poster, 'poster' => $product->getPoster(),
'name' => $product->name['ru'] '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 * @param Compilation $compilation

View File

@@ -283,11 +283,7 @@ class Controller extends ExController
foreach ($product->childrens as $children) { foreach ($product->childrens as $children) {
foreach ($children->screens as $screen) { foreach ($children->screens as $screen) {
$screen->sizeText = $screen->size / 1024 . 'Kb'; $screen->sizeText = $screen->size / 1024 . 'Kb';
if (env('FILESYSTEM_DISK') == 's3') { $screen->url = Storage::url($screen->path);
$screen->url = Storage::url($screen->path);
} else {
$screen->url = '/' . $screen->path;
}
$screen->type = "image/jpeg"; $screen->type = "image/jpeg";
} }
} }
@@ -318,15 +314,15 @@ class Controller extends ExController
try { try {
$this->dispatchSync(new UpdateJob($product, $request)); $this->dispatchSync(new UpdateJob($product, $request));
$this->dispatchSync(new ChildUpdateJob($request, $product)); $this->dispatchSync(new ChildUpdateJob($request, $product));
$this->charSync($product, $request->characteristics);
$this->dispatchSync(new DeletesJob($request));
} catch (Exception $e) { } catch (Exception $e) {
return Response::json([ 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')); $this->info(trans('admin.messages.updated'));
return response()->json([ return response()->json([
@@ -394,8 +390,12 @@ class Controller extends ExController
$article_number = empty($request->get('article_number')) ? null : $request->get('article_number'); $article_number = empty($request->get('article_number')) ? null : $request->get('article_number');
if ($category) { if ($category) {
$categoryFind = Category::find($category); $categoryFind = Category::withTrashed()->find($category);
list($categoryFind, $category_id) = $this->categoryQuery->getCategoriesAndCategoryMainId($categoryFind); if ($categoryFind) {
list($categoryFind, $category_id) = $this->categoryQuery->getCategoriesAndCategoryMainId($categoryFind);
} else {
$category_id = [];
}
} else { } else {
$category_id = []; $category_id = [];
} }

View File

@@ -40,14 +40,14 @@ class Update extends FormRequest
return Str::slug($this->get('name')['uz']); return Str::slug($this->get('name')['uz']);
} }
public function getImage(Category $category): string public function getImage(Category $category): ?string
{ {
if ($this->hasFile('image')) { if ($this->hasFile('image')) {
Storage::delete($category->image); Storage::delete($category->image);
return (string) $this->file('image')->store('uploads/categories'); return (string) $this->file('image')->store('uploads/categories');
} else {
return 'null';
} }
return $category->image;
} }
public function getFilterPower() public function getFilterPower()

View File

@@ -22,7 +22,8 @@ class Store extends FormRequest
return [ return [
'title' => 'array', 'title' => 'array',
'title.*' => 'required', 'title.*' => 'required',
'published' => 'required', 'published' => 'nullable',
'products' => 'nullable|array',
//'category_id' => 'required' //'category_id' => 'required'
]; ];
} }
@@ -40,7 +41,7 @@ class Store extends FormRequest
*/ */
public function getPublished(): bool public function getPublished(): bool
{ {
return $this->get('published'); return filter_var($this->get('published', false), FILTER_VALIDATE_BOOLEAN);
} }
@@ -49,8 +50,8 @@ class Store extends FormRequest
*/ */
public function getCategory() public function getCategory()
{ {
if ($this->get('category_id')) { if ($this->get('category_id') && $this->get('category_id') != 0) {
$this->get('category_id'); return $this->get('category_id');
} }
return null; return null;

View File

@@ -22,7 +22,8 @@ class Update extends FormRequest
return [ return [
'title' => 'array', 'title' => 'array',
'title.*' => 'required', 'title.*' => 'required',
'published' => 'required', 'published' => 'nullable',
'products' => 'nullable|array',
//'category_id' => 'required', //'category_id' => 'required',
]; ];
} }
@@ -40,14 +41,14 @@ class Update extends FormRequest
*/ */
public function getPublished(): bool public function getPublished(): bool
{ {
return $this->get('published'); return filter_var($this->get('published', false), FILTER_VALIDATE_BOOLEAN);
} }
public function getCategory() public function getCategory()
{ {
if ($this->get('category_id')) { if ($this->get('category_id') && $this->get('category_id') != 0) {
$this->get('category_id'); return $this->get('category_id');
} }
return null; return null;

View File

@@ -35,8 +35,8 @@ class Update
$category->name = $request->getName(); $category->name = $request->getName();
$category->slug = $request->getSlug(); $category->slug = $request->getSlug();
$category->position = $request->getPosition(); $category->position = $request->getPosition();
$category->image = $request->getImage($category); $category->image = $this->image;
// $category->parent_id = $request->getParentId(); $category->parent_id = $request->getParentId();
// $category->popular = $request->getPopular(); // $category->popular = $request->getPopular();
$category->published = $request->getPublished(); $category->published = $request->getPublished();
$category->is_filter_power = $request->getFilterPower(); $category->is_filter_power = $request->getFilterPower();
@@ -45,8 +45,6 @@ class Update
$category->keywords = $request->keywords; $category->keywords = $request->keywords;
$category->title_seo = $request->title_seo; $category->title_seo = $request->title_seo;
$category->image = $this->image;
$category->save(); $category->save();
if (isset($request->brands)) { if (isset($request->brands)) {

View File

@@ -36,8 +36,10 @@ class Store
$map = array_map(function ($product) { $map = array_map(function ($product) {
return $product['id']; return $product['id'];
}, $this->request->products); }, $this->request->products ?? []);
$compilation->products()->attach($map); if (!empty($map)) {
$compilation->products()->attach($map);
}
} }
} }

View File

@@ -35,20 +35,12 @@ class Update
'category_id' => $this->request->getCategory() 'category_id' => $this->request->getCategory()
]); ]);
$detach = Compilation::find($this->compilation->id);
$detach->loadMissing(['products:id']);
$compilation = Compilation::find($this->compilation->id); $compilation = Compilation::find($this->compilation->id);
$map = array_map(function ($product) { $map = array_map(function ($product) {
return $product['id']; return $product['id'];
}, $this->request->products); }, $this->request->products ?? []);
$detach = array_map(function ($product) { $compilation->products()->sync($map);
return $product['id'];
}, $detach->products->toArray());
$compilation->products()->detach($detach);
$compilation->products()->attach($map);
} }
} }

View File

@@ -62,12 +62,7 @@ class Brand extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(config('filesystems.default'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
;
return (string) '/' . $this->image;
} }
return (string) 'images/no_brend.png'; return (string) 'images/no_brend.png';

View File

@@ -147,11 +147,7 @@ class Category extends Model
public function getImage(): string public function getImage(): string
{ {
if (!in_array($this->image, ['null', null])) { if (!in_array($this->image, ['null', null])) {
if (in_array(config('filesystems.default'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return config('app.url') . '/' . $this->image;
} }
return config('app.url') . '/images/nophoto.jpg'; return config('app.url') . '/images/nophoto.jpg';

View File

@@ -58,6 +58,11 @@ class Compilation extends Model
return $this->belongsToMany(Product::class, 'compilation_products')->where('published', true)->limit(10); return $this->belongsToMany(Product::class, 'compilation_products')->where('published', true)->limit(10);
} }
public function dashboardProducts()
{
return $this->belongsToMany(Product::class, 'compilation_products');
}
/** /**

View File

@@ -30,12 +30,9 @@ class ContractTemplate extends Model
public function full_path(): string public function full_path(): string
{ {
if (!empty($this->path)) { if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->path);
return Storage::url($this->path);
}
return '/' . $this->path;
} }
return asset('storage/' . $this->path); return null;
} }
} }

View File

@@ -47,10 +47,7 @@ class File extends Model
public function getPath() public function getPath()
{ {
if (!empty($this->path)) { if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->path);
return Storage::url($this->path);
}
return (string) $this->path;
} }
return null; return null;
@@ -62,10 +59,7 @@ class File extends Model
public function getPathThumb() public function getPathThumb()
{ {
if (!empty($this->path_thumb)) { if (!empty($this->path_thumb)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->path_thumb);
return Storage::url($this->path_thumb);
}
return (string) $this->path_thumb;
} }
return null; return null;

View File

@@ -36,11 +36,7 @@ class OrderContract extends Model
public function getPath() public function getPath()
{ {
if (!empty($this->path)) { if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->path);
return Storage::url($this->path);
}
return env('APP_URL') . '/storage/' . $this->path;
} }
return null; return null;

View File

@@ -52,11 +52,7 @@ class Partner extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return (string) $this->image;
} }
return (string) 'images/no_brend.png'; return (string) 'images/no_brend.png';

View File

@@ -70,11 +70,7 @@ class PaymentSystemItem extends Model
public function getLogo(): string public function getLogo(): string
{ {
if (!empty($this->logo)) { if (!empty($this->logo)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->logo);
return Storage::url($this->logo);
}
return env('APP_URL').'/'.$this->logo;
} }
return '/images/nophoto.jpg'; return '/images/nophoto.jpg';

View File

@@ -56,11 +56,7 @@ class Post extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return $this->image;
} }
return '/images/nophoto.jpg'; return '/images/nophoto.jpg';

View File

@@ -236,10 +236,7 @@ class Product extends Model
public function getPoster(): string public function getPoster(): string
{ {
if (!empty($this->poster)) { if (!empty($this->poster)) {
if (in_array(config('filesystems.default'), ['s3', 'minio'])) { return Storage::url($this->poster);
return Storage::url($this->poster);
}
return config('app.url') . '/' . $this->poster;
} }
return config('app.url') . '/images/no_product.jpg'; return config('app.url') . '/images/no_product.jpg';
@@ -248,10 +245,7 @@ class Product extends Model
public function getDataSheet() public function getDataSheet()
{ {
if (!empty($this->data_sheet) and ($this->data_sheet != null and $this->data_sheet != "null")) { if (!empty($this->data_sheet) and ($this->data_sheet != null and $this->data_sheet != "null")) {
if (in_array(config('filesystems.default'), ['s3', 'minio'])) { return Storage::url($this->data_sheet);
return Storage::url($this->data_sheet);
}
return config('app.url') . '/' . $this->data_sheet;
} }
return null; return null;
} }
@@ -259,10 +253,7 @@ class Product extends Model
public function getPosterThumb(): string public function getPosterThumb(): string
{ {
if (!empty($this->poster_thumb)) { if (!empty($this->poster_thumb)) {
if (in_array(config('filesystems.default'), ['s3', 'minio'])) { return Storage::url($this->poster_thumb);
return Storage::url($this->poster_thumb);
}
return config('app.url') . '/' . $this->poster_thumb;
} }
return config('app.url') . '/images/no_product.jpg'; return config('app.url') . '/images/no_product.jpg';

View File

@@ -58,10 +58,7 @@ class Screen extends Model
public function getPath(): string public function getPath(): string
{ {
if (!empty($this->path)) { if (!empty($this->path)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->path);
return Storage::url($this->path);
}
return (string) $this->path;
} }
return (string) 'image/no_screen.png'; return (string) 'image/no_screen.png';
@@ -73,10 +70,7 @@ class Screen extends Model
public function getPathThumb(): string public function getPathThumb(): string
{ {
if (!empty($this->path_thumb)) { if (!empty($this->path_thumb)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->path_thumb);
return Storage::url($this->path_thumb);
}
return (string) $this->path_thumb;
} }
return (string) 'image/no_screen_thumb.png'; return (string) 'image/no_screen_thumb.png';

View File

@@ -61,10 +61,7 @@ class Service extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return (string) $this->image;
} }
return (string) 'images/no_brend.png'; return (string) 'images/no_brend.png';

View File

@@ -45,10 +45,7 @@ class Slider extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return $this->image;
} }
return '/images/nophoto.jpg'; return '/images/nophoto.jpg';

View File

@@ -47,10 +47,7 @@ class SpecialOffer extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return (string) $this->image;
} }
return (string) 'images/nophoto.png'; return (string) 'images/nophoto.png';

View File

@@ -44,10 +44,7 @@ class UsefulInfo extends Model
public function getImage(): string public function getImage(): string
{ {
if (!empty($this->image)) { if (!empty($this->image)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->image);
return Storage::url($this->image);
}
return (string) $this->image;
} }
return (string) 'images/no_brend.png'; return (string) 'images/no_brend.png';

View File

@@ -63,10 +63,7 @@ class UsefulInfoItem extends Model
public function getFile(): string public function getFile(): string
{ {
if (!empty($this->file_url)) { if (!empty($this->file_url)) {
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) { return Storage::url($this->file_url);
return Storage::url($this->file_url);
}
return '/' . $this->file_url;
} }
return '/images/no_product.jpg'; return '/images/no_product.jpg';

View File

@@ -9,11 +9,13 @@ server {
root /quyoshli/public; root /quyoshli/public;
index index.php; index index.php;
# MinIO bucket proxy — serves files over HTTPS # Final MinIO proxy fix - ^~ is mandatory to override regex blocks
location /quyoshli/ { location ^~ /quyoshli/ {
proxy_pass http://quyoshli-minio:9100/quyoshli/; proxy_set_header Host $proxy_host;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://quyoshli-minio:9100;
proxy_buffering off; proxy_buffering off;
} }
@@ -22,10 +24,6 @@ server {
try_files $uri /$uri /index.php$is_args$args; try_files $uri /$uri /index.php$is_args$args;
} }
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ { location ~ \.php$ {
fastcgi_pass quyoshli:9000; fastcgi_pass quyoshli:9000;
fastcgi_index index.php; fastcgi_index index.php;

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -34,7 +34,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<label for="category">Категория</label> <label for="category">Категория</label>
<select id="category" class="form-control" v-model="category_id"> <select id="category" class="form-control" v-model="category_id" @change="SearchProduct('')">
<option value="0">Все</option> <option value="0">Все</option>
<option v-for="category in categories" :value="category.id"> <option v-for="category in categories" :value="category.id">
{{ category.name.ru }} {{ category.name.ru }}
@@ -194,19 +194,17 @@
async SearchProduct(query) { async SearchProduct(query) {
let name = query; let name = query;
if (name.length > 0) { axios.post('/dashboard/compilations/product/search', { name: name, category_id: this.category_id})
axios.post('/dashboard/compilations/product/search', { name: name}) .then((response) => {
.then((response) => { if (response.data.status) {
if (response.data.status) { this.products = response.data.products;
this.products = response.data.products;
}
}).catch((error) => {
if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
} }
}); }).catch((error) => {
} if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
}
});
console.log(query); console.log(query);
}, },

View File

@@ -34,7 +34,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<label for="category">Категория</label> <label for="category">Категория</label>
<select id="category" class="form-control" v-model="category_id"> <select id="category" class="form-control" v-model="category_id" @change="SearchProduct('')">
<option value="0">Все</option> <option value="0">Все</option>
<option v-for="category in categories" :value="category.id"> <option v-for="category in categories" :value="category.id">
{{ category.name.ru }} {{ category.name.ru }}
@@ -196,19 +196,17 @@
async SearchProduct(query) { async SearchProduct(query) {
let name = query; let name = query;
if (name.length > 0) { axios.post('/dashboard/compilations/product/search', { name: name, category_id: this.category_id})
axios.post('/dashboard/compilations/product/search', { name: name}) .then((response) => {
.then((response) => { if (response.data.status) {
if (response.data.status) { this.products = response.data.products;
this.products = response.data.products;
}
}).catch((error) => {
if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
} }
}); }).catch((error) => {
} if (error.response) {
this.error = true;
this.errors = error.response.data.errors;
}
});
console.log(query); console.log(query);
}, },

View File

@@ -137,168 +137,67 @@ export default {
subCategories: [], subCategories: [],
category: null, category: null,
subCategory: null, subCategory: null,
currentParentId: null,
}; };
}, },
methods: { methods: {
async SendForm() { async SendForm() {
const formData = new FormData();
for (var i = 0; i < this.categories.length; i++) {
formData.append(
"categories[" + i + "][id]",
this.categories[i].id
);
formData.append(
"categories[" + i + "][position]",
this.categories[i].position
);
formData.append(
"categories[" + i + "][parent_id]",
this.categories[i].parent_id
);
if (this.categories[i].children.length > 0) {
for (
var c = 0;
c < this.categories[i].children.length;
c++
) {
formData.append(
"categories[" + i + "][children][" + c + "][id]",
this.categories[i].children[c].id
);
formData.append(
"categories[" +
i +
"][children][" +
c +
"][position]",
this.categories[i].children[c].position
);
formData.append(
"categories[" +
i +
"][children][" +
c +
"][parent_id]",
this.categories[i].children[c].parent_id
);
if (
this.categories[i].children[c].children.length > 0
) {
for (
var w = 0;
w <
this.categories[i].children[c].children.length;
w++
) {
formData.append(
"categories[" +
i +
"][children][" +
c +
"][children][" +
w +
"][id]",
this.categories[i].children[c].children[w]
.id
);
formData.append(
"categories[" +
i +
"][children][" +
c +
"][children][" +
w +
"][position]",
this.categories[i].children[c].children[w]
.position
);
formData.append(
"categories[" +
i +
"][children][" +
c +
"][children][" +
w +
"][parent_id]",
this.categories[i].children[c].children[w]
.parent_id
);
}
}
}
}
}
const { data } = await axios.post( const { data } = await axios.post(
"/dashboard/categories/position", "/dashboard/categories/position",
formData {
categories: this.normalizeTree(this.categoriesData, null, 0),
}
); );
if (data.status) { if (data.status) {
// window.location.href = "/dashboard/categories"; window.location.reload();
} }
}, },
Change() { Change() {
for (var i = 0; i < this.categories.length; i++) { this.normalizeTree(this.categoriesData, null, 0);
var num = i + 1; },
this.categories[i].position = num; normalizeTree(categories, parentId, level) {
this.categories[i].droppable = true; return categories.map((category, index) => {
category.position = index + 1;
category.parent_id = parentId;
category.droppable = level < 2;
if (this.categories[i].children.length > 0) { const children = Array.isArray(category.children)
for ( ? this.normalizeTree(category.children, category.id, level + 1)
var c = 0; : [];
c < this.categories[i].children.length;
c++
) {
var numm = c + 1;
this.categories[i].children[c].position = numm;
this.categories[i].children[c].parent_id =
this.categories[i].id;
this.categories[i].children[c].droppable = true;
if ( return {
this.categories[i].children[c].children.length > 0 id: category.id,
) { position: category.position,
for ( parent_id: category.parent_id,
var w = 0; children,
w < };
this.categories[i].children[c].children.length; });
w++
) {
var nummm = w + 1;
this.categories[i].children[c].children[
w
].position = nummm;
this.categories[i].children[c].children[
w
].parent_id = this.categories[i].children[c].id;
this.categories[i].children[c].children[
w
].droppable = false;
}
}
}
}
}
}, },
handleMainCategory() { handleMainCategory() {
if (this.category) { if (this.category) {
this.categories = this.category.children; this.categories = this.category.children;
this.subCategories = this.category.children; this.subCategories = this.category.children;
this.currentParentId = this.category.id;
} else { } else {
this.categories = this.categoriesData; this.categories = this.categoriesData;
this.subCategories = null; this.subCategories = null;
this.currentParentId = null;
} }
}, },
handleSubCategory() { handleSubCategory() {
if (this.subCategory) this.categories = this.subCategory.children; if (this.subCategory) {
else this.categories = this.category.children; this.categories = this.subCategory.children;
this.currentParentId = this.subCategory.id;
} else {
this.categories = this.category.children;
this.currentParentId = this.category ? this.category.id : null;
}
}, },
}, },
}; };

View File

@@ -111,7 +111,6 @@
type="file" type="file"
name="image" name="image"
@change="ImageFile($event)" @change="ImageFile($event)"
onchange="PreviewImage();"
/> />
<label <label
class="custom-file-label" class="custom-file-label"
@@ -126,6 +125,7 @@
<div class="text-center"> <div class="text-center">
<img <img
id="uploadPreview" id="uploadPreview"
:src="category.imagePreview"
style=" style="
width: 300px; width: 300px;
height: auto; height: auto;
@@ -707,6 +707,7 @@ export default {
}, },
image: null, image: null,
imagePreview: null,
}, },
char: [], char: [],
@@ -798,6 +799,12 @@ export default {
ImageFile(event) { ImageFile(event) {
this.category.image = event.target.files[0]; this.category.image = event.target.files[0];
if (this.category.image) {
this.category.imagePreview = URL.createObjectURL(
this.category.image
);
}
}, },
addChar() { addChar() {

View File

@@ -111,7 +111,6 @@
type="file" type="file"
name="image" name="image"
@change="ImageFile($event)" @change="ImageFile($event)"
onchange="PreviewImage();"
/> />
<label <label
class="custom-file-label" class="custom-file-label"
@@ -811,6 +810,10 @@ export default {
ImageFile(event) { ImageFile(event) {
this.file = event.target.files[0]; this.file = event.target.files[0];
if (this.file) {
this.category.image_url = URL.createObjectURL(this.file);
}
}, },
addChar() { addChar() {

View File

@@ -309,7 +309,6 @@
<input <input
class="form-control" class="form-control"
@change="posterFile($event)" @change="posterFile($event)"
onchange="PreviewImage();"
type="file" type="file"
id="poster" id="poster"
/> />
@@ -670,6 +669,7 @@
:theme="'default'" :theme="'default'"
:multiple="true" :multiple="true"
:deletable="true" :deletable="true"
:linkable="true"
:meta="true" :meta="true"
:accept="'image/*'" :accept="'image/*'"
:maxSize="'10MB'" :maxSize="'10MB'"
@@ -679,10 +679,13 @@
type: 'Invalid file type. Only images or zip Allowed', type: 'Invalid file type. Only images or zip Allowed',
size: 'Files should not exceed 10MB in size', size: 'Files should not exceed 10MB in size',
}" }"
@select="
filesSelected($event, index)
"
@beforedelete=" @beforedelete="
onBeforeDelete(
$event,
index
)
"
@delete="
fileDeleted($event, index) fileDeleted($event, index)
" "
v-model="color.screens" v-model="color.screens"
@@ -1352,18 +1355,6 @@ export default {
} }
} }
if (this.products.childrens[i].filesDataForUpload) {
for (
let f = 0;
f < this.products.childrens[i].filesDataForUpload.length;
f++
) {
formData.append(
"colors[" + i + "][screens][new_" + f + "][image]",
this.products.childrens[i].filesDataForUpload[f].file
);
}
}
} }
for (let i = 0; i < this.deletes.childrens.length; i++) { for (let i = 0; i < this.deletes.childrens.length; i++) {
@@ -1394,7 +1385,12 @@ export default {
.catch((error) => { .catch((error) => {
if (error.response) { if (error.response) {
this.error = true; this.error = true;
this.errors = error.response.data.errors; this.errors = error.response.data.errors || {
product: [
error.response.data.messages ||
"Ошибка при сохранении",
],
};
} }
}); });
}, },
@@ -1488,26 +1484,19 @@ export default {
this.products.childrens[index].sizes.splice(indexx, 1); this.products.childrens[index].sizes.splice(indexx, 1);
}, },
filesSelected: function (filesDataNewlySelected, index) { onBeforeDelete: function (fileData, index) {
let validFilesData = filesDataNewlySelected.filter( const agent = Array.isArray(this.$refs.vueFileAgent)
(fileData) => !fileData.error ? this.$refs.vueFileAgent[index]
); : this.$refs.vueFileAgent;
this.products.childrens[index].filesDataForUpload =
this.products.childrens[index].filesDataForUpload.concat( if (agent) {
validFilesData agent.deleteFileRecord(fileData);
); }
}, },
fileDeleted: function (fileData, index) { fileDeleted: function (fileData) {
let i = this.products.childrens[index].screens.indexOf(fileData); if (fileData.id && !this.deletes.screens.includes(fileData.id)) {
this.deletes.screens.push(fileData.id);
if (i !== -1) {
this.products.childrens[index].screens.splice(i, 1);
let id = fileData.id ? fileData.id : null;
if (fileData.id) {
this.deletes.screens.push(id);
}
} }
}, },
}, },

View File

@@ -324,7 +324,6 @@
<input <input
class="form-control" class="form-control"
@change="posterFile($event)" @change="posterFile($event)"
onchange="PreviewImage();"
required required
type="file" type="file"
id="poster" id="poster"
@@ -684,6 +683,7 @@
:theme="'default'" :theme="'default'"
:multiple="true" :multiple="true"
:deletable="true" :deletable="true"
:linkable="true"
:meta="true" :meta="true"
:accept="'image/*'" :accept="'image/*'"
:maxSize="'10MB'" :maxSize="'10MB'"
@@ -693,10 +693,13 @@
type: 'Invalid file type. Only images or zip Allowed', type: 'Invalid file type. Only images or zip Allowed',
size: 'Files should not exceed 10MB in size', size: 'Files should not exceed 10MB in size',
}" }"
@select="
filesSelected($event, index)
"
@beforedelete=" @beforedelete="
onBeforeDelete(
$event,
index
)
"
@delete="
fileDeleted($event, index) fileDeleted($event, index)
" "
v-model="color.screens" v-model="color.screens"
@@ -1278,18 +1281,6 @@ export default {
} }
} }
if (this.product.colors[i].filesDataForUpload) {
for (
let f = 0;
f < this.product.colors[i].filesDataForUpload.length;
f++
) {
formData.append(
"colors[" + i + "][screens][new_" + f + "][image]",
this.product.colors[i].filesDataForUpload[f].file
);
}
}
} }
for (var i = 0; i < this.characteristics.length; i++) { for (var i = 0; i < this.characteristics.length; i++) {
@@ -1442,25 +1433,17 @@ export default {
// this.$refs.vueFileAgent.deleteUpload(this.uploadUrl, this.uploadHeaders, fileData); // this.$refs.vueFileAgent.deleteUpload(this.uploadUrl, this.uploadHeaders, fileData);
// }, // },
filesSelected: function (filesDataNewlySelected, index) { onBeforeDelete: function (fileData, index) {
var validFilesData = filesDataNewlySelected.filter( const agent = Array.isArray(this.$refs.vueFileAgent)
(fileData) => !fileData.error ? this.$refs.vueFileAgent[index]
); : this.$refs.vueFileAgent;
this.product.colors[index].filesDataForUpload =
this.product.colors[index].filesDataForUpload.concat(
validFilesData
);
},
fileDeleted: function (fileData, index) { if (agent) {
var i = agent.deleteFileRecord(fileData);
this.product.colors[index].filesDataForUpload.indexOf(fileData);
if (i !== -1) {
this.product.colors[index].filesDataForUpload.splice(i, 1);
} else {
this.deleteUploadedFile(fileData);
} }
}, },
fileDeleted: function () {},
}, },
}; };
</script> </script>

View File

@@ -118,6 +118,17 @@
</li> </li>
@endif @endif
@can('view', 'sliders')
<li class="nav-item {{ active([route('dashboard.sliders'), route('dashboard.sliders') . '/*']) }}">
<a href="{{ route('dashboard.sliders') }}">
<i class="feather icon-image"></i>
<span class="menu-title">
@lang('admin.slider.title')
</span>
</a>
</li>
@endcan
@can('view', 'users') @can('view', 'users')
<li class="nav-item {{ active([route('dashboard.users'), route('dashboard.users') . '/*']) }}"><a <li class="nav-item {{ active([route('dashboard.users'), route('dashboard.users') . '/*']) }}"><a
href="{{ route('dashboard.users') }}"> href="{{ route('dashboard.users') }}">

View File

@@ -29,7 +29,7 @@
<div id="app"> <div id="app">
<product-edit :product="{{ json_encode($product) }}" :brands="{{ json_encode($brands) }}" <product-edit :product="{{ json_encode($product) }}" :brands="{{ json_encode($brands) }}"
:categories="{{ json_encode($categories) }}" :colors="{{ json_encode($colors) }}" :categories="{{ json_encode($categories) }}" :colors="{{ json_encode($colors) }}"
:back-url="{{ json_encode(url()->previous()) }}" :measurement="{{ json_encode($measurement) }}"></product-edit> :back-url="{{ json_encode(route('dashboard.products')) }}" :measurement="{{ json_encode($measurement) }}"></product-edit>
</div> </div>
@endsection @endsection