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')
+
+
+
+ Название товара: {{ $good->title }} ID: ({{ $good->id }})
+
+
+
+
+
+@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 @@
+
+ Дополнительные картинки
+ Добавить картинку в галерею
+
+
+
+ ID |
+ Фото |
+ Действия |
+
+
+
+ @if ($good->images->count())
+ @foreach($good->images as $img)
+
+ =$img->id?> |
+ |
+ Удалить |
+
+ @endforeach
+ @else
+
+ - |
+ - |
+ - |
+
+ @endif
+
+
@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')
+
+
+
+ Товары
+
+
+ Создать товар
+
+
+
+
+
+ ID |
+ Фото |
+ Категория |
+ Товар |
+ Дата создания |
+ Действия |
+
+
+
+ @if ($goods->count())
+ @foreach($goods as $good)
+
+ {{ $good->id }} |
+ if (empty($good->image)) {?>Нет фото} else {?>
+
+
+ }?> |
+ {{ $good->category->name }} |
+ {{ $good->title }} |
+ {{ $good->created_at }} |
+
+ |
+
+ @endforeach
+ @else
+
+ - |
+ - |
+ - |
+ - |
+ - |
+ - |
+
+ @endif
+
+
+
+
+ {{ $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 @@
+ @empty($good->image)
+
+ @else
-
+
-
+ @endif
+
+ @if ($images->count())
+ @foreach($images as $image)
+
+
+
+
+
+ @endforeach
+ @endif
+