From 0cbcbfbe0ee396561669179c3c6624283fa80522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Thu, 20 Apr 2023 14:40:41 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0?= =?UTF-8?q?=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BA=D0=B0=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=D0=BA=D0=B8=20=D0=B2=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=B5=20=D1=83=20=D0=BE=D0=B1=D0=BE=D1=80=D1=83=D0=B4=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F,=20=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=B2=D1=8B=D0=BF=D0?= =?UTF-8?q?=B0=D0=B4=D0=B0=D1=8E=D1=89=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/GoodController.php | 46 ++++ app/Http/Controllers/MainController.php | 36 ++- app/Models/Good.php | 7 + app/Models/Images.php | 4 + app/Providers/ComposerServiceProvider.php | 2 + resources/views/admin/goods/add_image.blade.php | 26 ++ resources/views/admin/goods/edit.blade.php | 29 +++ resources/views/admin/goods/form.blade.php | 4 +- resources/views/admin/goods/lookin.blade.php | 66 +++++ resources/views/good.blade.php | 315 +++++++++++++++-------- resources/views/layout/admin.blade.php | 11 +- resources/views/layout/site.blade.php | 17 +- resources/views/part/categories_menu.blade.php | 19 ++ resources/views/simple_good.blade.php | 103 +++++--- routes/web.php | 22 +- 15 files changed, 547 insertions(+), 160 deletions(-) create mode 100644 resources/views/admin/goods/add_image.blade.php create mode 100644 resources/views/admin/goods/lookin.blade.php create mode 100644 resources/views/part/categories_menu.blade.php diff --git a/app/Http/Controllers/Admin/GoodController.php b/app/Http/Controllers/Admin/GoodController.php index 7f3ba6f..3d0a83a 100644 --- a/app/Http/Controllers/Admin/GoodController.php +++ b/app/Http/Controllers/Admin/GoodController.php @@ -5,8 +5,12 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\GoodsRequest; use App\Models\Good; +use App\Models\Images; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Validator; class GoodController extends Controller { @@ -108,4 +112,46 @@ class GoodController extends Controller $good->delete(); return redirect()->route('admin.goods.index'); } + + public function images_good(Good $good) { + return view('admin.goods.add_image', compact('good')); + } + + public function good_add_img(Good $good, Request $request) { + $rules = [ + 'image' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите картинку!', + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.img.good', ['good' => $good->id]) + ->withErrors($validator); + } else { + $images = new Images(); + $images->good_id = $good->id; + $images->image = $request->file('image')->store('goods', 'public'); + $images->sample = $request->sample; + $images->save(); + + return redirect()->route('admin.goods.edit', ['good' => $good->id]); + } + } + + public function good_del_img($id, Good $good) { + if (!empty($id)) { + $id = (int)$id; + $item = Images::find($id); + Storage::delete($item->image); + $item->delete(); + Session::flash('message','Картинка была успешно удалена!'); + + return redirect()->route('admin.goods.edit', ['good' => $good->id]); + + } else { + return redirect()->route('admin.goods.edit', ['good' => $good->id]); + } + } } diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 6683262..7926358 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -6,8 +6,12 @@ use App\Models\Banner; use App\Models\Category; use App\Models\Good; use App\Models\Good_Look; +use App\Models\Images; use App\Models\News; +use App\Models\Project; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Redirect; use Symfony\Component\HttpFoundation\Session\Storage; class MainController extends Controller @@ -121,10 +125,36 @@ class MainController extends Controller $looking->goods_id = $good->id; $looking->save(); - return view('good', compact('good')); + $lookin = Good_Look::query()->orderByDesc('id')->limit(4)->pluck('goods_id') + ->toArray(); + $lookin_good = Good::query()->whereIn('id', $lookin)->get(); + + $projects = Project::query()->orderByDesc('id')->paginate(10); + + $sample = Images::query()->where('sample', '=', '1')->where('good_id', '=', $good->id)->get(); + $images = Images::query()->where('sample', '=', '0')->where('good_id', '=', $good->id)->get(); + + $accessory = Good::query()->where('accessory_id', '=', $good->id)->limit(8)->get(); + $tooling = Good::query()->where('tooling_id', '=', $good->id)->limit(8)->get(); + $also_good = Good::query()->where('category_id', '=', $good->category_id)->limit(4)->get(); + + return view('good', compact('good', 'accessory', 'tooling', 'also_good', + 'sample', 'images', 'lookin_good', 'projects')); + } + + public function simple_good(Good $good) { + $looking = new Good_Look(); + $looking->goods_id = $good->id; + $looking->save(); + + $lookin = Good_Look::query()->orderByDesc('id')->limit(4)->pluck('goods_id') + ->toArray(); + $lookin_good = Good::query()->whereIn('id', $lookin)->get(); + + return view('simple_good', compact('good', 'lookin_good')); } - public function simple_good() { - return view('simple_good'); + public function online() { + return redirect()->back(); } } diff --git a/app/Models/Good.php b/app/Models/Good.php index 4719883..01a5e38 100644 --- a/app/Models/Good.php +++ b/app/Models/Good.php @@ -19,4 +19,11 @@ class Good extends Model public function category() { return $this->belongsTo(Category::class, 'category_id'); } + + /* + * Связь объектов товаров с фотогалереей + */ + public function images() { + return $this->hasMany(Images::class); + } } diff --git a/app/Models/Images.php b/app/Models/Images.php index 35c482f..e43bcac 100644 --- a/app/Models/Images.php +++ b/app/Models/Images.php @@ -8,4 +8,8 @@ use Illuminate\Database\Eloquent\Model; class Images extends Model { use HasFactory; + + public function goods() { + return $this->belongsTo(Good::class); + } } diff --git a/app/Providers/ComposerServiceProvider.php b/app/Providers/ComposerServiceProvider.php index 2fec28d..e2b06c1 100644 --- a/app/Providers/ComposerServiceProvider.php +++ b/app/Providers/ComposerServiceProvider.php @@ -23,6 +23,8 @@ class ComposerServiceProvider extends ServiceProvider 'admin.part.parents', //выбор родителя категории при редактировании 'admin.part.all-ctgs', //все категории в административной части 'admin.part.category_id', + 'layout.site', + 'layout.admin', ]; View::composer($views, function($view) { diff --git a/resources/views/admin/goods/add_image.blade.php b/resources/views/admin/goods/add_image.blade.php new file mode 100644 index 0000000..a580826 --- /dev/null +++ b/resources/views/admin/goods/add_image.blade.php @@ -0,0 +1,26 @@ +@extends('layout.admin', ['title' => 'Создание доп.картинки товара']) + +@section('content') +
+
+ + + +
+
+@endsection diff --git a/resources/views/admin/goods/edit.blade.php b/resources/views/admin/goods/edit.blade.php index d6f6c17..ca1ab5b 100644 --- a/resources/views/admin/goods/edit.blade.php +++ b/resources/views/admin/goods/edit.blade.php @@ -9,6 +9,35 @@ + +

Дополнительные картинки

+ Добавить картинку в галерею + + + + + + + + + + @if ($good->images->count()) + @foreach($good->images as $img) + + + + + + @endforeach + @else + + + + + + @endif + +
IDФотоДействия
id?>Удалить
---
@endsection diff --git a/resources/views/admin/goods/form.blade.php b/resources/views/admin/goods/form.blade.php index 900d154..a000832 100644 --- a/resources/views/admin/goods/form.blade.php +++ b/resources/views/admin/goods/form.blade.php @@ -225,9 +225,9 @@ Ошибка
-@isset($category->image) +@isset($good->image)
- +
@endisset diff --git a/resources/views/admin/goods/lookin.blade.php b/resources/views/admin/goods/lookin.blade.php new file mode 100644 index 0000000..db21735 --- /dev/null +++ b/resources/views/admin/goods/lookin.blade.php @@ -0,0 +1,66 @@ +@extends('layout.admin', ['title' => 'Доп.картинки у товара']) + +@section('content') +
+
+
+

+ + + + + + + + + + + + + + @if ($goods->count()) + @foreach($goods as $good) + + + + + + + + + @endforeach + @else + + + + + + + + + @endif + + +
IDФотоКатегорияТоварДата созданияДействия
{{ $good->id }}image)) {?>Нет фото + + + {{ $good->category->name }}{{ $good->title }}{{ $good->created_at }}
+ + Редактировать + | + @csrf + @method('DELETE') + +
+
------
+ + {{ $goods->onEachSide(1)->links('catalogs.paginate') }} + +
+
+

+@endsection diff --git a/resources/views/good.blade.php b/resources/views/good.blade.php index 00b6a96..20cf887 100644 --- a/resources/views/good.blade.php +++ b/resources/views/good.blade.php @@ -434,12 +434,26 @@

- Установка лазерной - резки GWEIKE, - серия LF 6025GH + {{ $good->title }}

Производитель

- -

Optimum

+ +

{{ $good->manufacturer }}

- 250 990 ₽ -

- 250 999 ₽ -

+ @if ((!empty($good->price_old)) && ($good->price_old > 0)) + {{$good->price_old}} ₽ + @endif + + @if ((!empty($good->price)) && ($good->price > 0)) +

+ {{ $good->price }} ₽ +

+ @endif +
Купить @@ -554,7 +578,13 @@
-

Назначение

+

Описание


+ @if (!empty($good->description)) + {!! $good->description !!} + @else +

Здесь ничего нет

+ @endif +
+

Характеристики

- + @if (!empty($good->feature)) + {!! $good->feature !!} + @else +

Здесь ничего нет

+ @endif +

Образцы изделий

-

Изготовлено на установке лазерной резки gweike (lf6025gh)

+

Материалы представлены для ознакомления с работой станка

-
- -
-
+ @if ($sample->count()) + @foreach($sample as $image) +
+ +
+ @endforeach + @else +

Здесь ничего нет

+ @endif +
- +
- +
@@ -769,7 +811,12 @@

Комплектация

-
+ @if (!empty($good->equipment)) + {!! $good->equipment !!} + @else +

Здесь ничего нет.

+ @endif +
@@ -818,31 +865,41 @@
+ @if ($accessory->count()) + @foreach ($accessory as $acc)
+ @if (!empty($acc->image))
- +
-
+ -->
-

Установка лазерной - резки GWEIKE

+

{{ $acc->title }}

-

250 990 ₽

- + @if (!empty($acc->price)) +

{{ $acc->price }} ₽

+ @endif + В каталог
-
+ @endforeach + @else +

Здесь ничего нет

+ @endif +
-
+
- +
- +
@@ -1230,30 +1281,41 @@
-
+ @if ($tooling->count()) + @foreach ($tooling as $tool) +
+ @if (!empty($tool->image))
- +
-
+ src="./img/product/viewed/v-1-min.png" alt="">
-->
-

Автоматический стол перемещения X

+

{{$tool->title}}

-

250 990 ₽

- + @if (!empty($tool->price)) +

{{ $tool->price }} ₽

+ @endif + В каталог
-
+ @endforeach + @else +

Здесь ничего нет

+ @endif + +
-
+
- +
- +
@@ -1638,33 +1700,40 @@
+ @if ($also_good->count()) + @foreach($also_good as $agood)
+ @if (!empty($agood->image))
- +
-
+ src="./img/product/viewed/v-1-min.png" alt="">
-->
-

Установка лазерной - резки GWEIKE

+

{{ $agood->title }}

-

250 990 ₽

- +

{{ $agood->price }} ₽

+ В каталог
-
+ @endforeach + @else +

Здесь ничего нет

+ @endif +
- +
- +
@@ -1788,7 +1857,7 @@
-
+ + @if ($projects->count())

Реализованные проекты

+ @foreach ($projects as $project)
- -

Монтаж установки лазерной резки Gweike в Химках

+ +

{{ $project->title }}

Заказчик:

- Стройпромет + {{ $project->customer }}

Дата сдачи проекта:

- 01.09.2020 + {{ $project->date_project }}
-
+ @endforeach +
- +
- +
@@ -1990,7 +2063,9 @@
+ @endif + @if ($lookin_good->count())

@@ -1998,7 +2073,35 @@

-
+ @foreach ($lookin_good as $look) +
+
+
+
+
+
+ +
+ +
+
+
+
+
+

{{ $look->title }}

+
+

{{ $look->price }} ₽

+ +
+
+
+
+ @endforeach +
@@ -2148,7 +2251,7 @@
- + @endif
diff --git a/resources/views/layout/admin.blade.php b/resources/views/layout/admin.blade.php index 1b57621..9d9d87c 100644 --- a/resources/views/layout/admin.blade.php +++ b/resources/views/layout/admin.blade.php @@ -239,7 +239,8 @@
+ @if (!empty($good->feature)) + {!! $good->feature !!} + @else +

Здесь ничего нет

+ @endif + + @if ($lookin_good->count()) + @endif