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