Commit c5f46e4d5f4508c3382d88d021f57a2361a51f2c

Authored by Андрей Ларионов
1 parent e73374e878
Exists in master

Таблица просматриваемые товары и разделы на странице каталога

Showing 6 changed files with 125 additions and 49 deletions Side-by-side Diff

app/Http/Controllers/MainController.php
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers;
5 5 use App\Models\Banner;
6 6 use App\Models\Category;
7 7 use App\Models\Good;
  8 +use App\Models\Good_Look;
8 9 use App\Models\News;
9 10 use Illuminate\Http\Request;
10 11 use Symfony\Component\HttpFoundation\Session\Storage;
... ... @@ -48,7 +49,10 @@ class MainController extends Controller
48 49 $items = Category::all();
49 50 $goods = Good::query();
50 51 $articles = News::query()->where('status', '=', 'статья')->paginate(10);
51   - $reviews = News::query()->where('status', '=', 'отзыв')->paginate(3);
  52 + $reviews = News::query()->where('status', '=', 'отзыв')->paginate(10);
  53 + $lookin = Good_Look::query()->orderByDesc('id')->limit(4)->pluck('goods_id')
  54 + ->toArray();
  55 + $lookin_good = Good::query()->whereIn('id', $lookin)->get();
52 56  
53 57 if (!empty($request->filter)) {
54 58 $filter = json_decode($request->filter);
... ... @@ -72,13 +76,19 @@ class MainController extends Controller
72 76 }
73 77  
74 78 $mf = Good::select('manufacturer')->distinct()->pluck('manufacturer');
75   - return view('catalog', compact('items', 'goods', 'mf', 'articles', 'reviews'));
  79 + return view('catalog', compact('items', 'goods',
  80 + 'mf', 'articles', 'reviews', 'lookin_good'));
76 81 }
77 82  
78 83 public function catalog_detail(Category $category, Request $request) {
79 84 $items = Category::all();
80 85 $title = $category->name;
81 86 $goods = Good::query()->where('category_id', '=', $category->id);
  87 + $articles = News::query()->where('status', '=', 'статья')->paginate(10);
  88 + $reviews = News::query()->where('status', '=', 'отзыв')->paginate(10);
  89 + $lookin = Good_Look::query()->orderByDesc('id')->limit(4)->pluck('goods_id')
  90 + ->toArray();
  91 + $lookin_good = Good::query()->whereIn('id', $lookin)->get();
82 92  
83 93 if (!empty($request->filter)) {
84 94 $filter = json_decode($request->filter);
... ... @@ -102,11 +112,16 @@ class MainController extends Controller
102 112 }
103 113  
104 114 $mf = Good::select('manufacturer')->distinct()->where('category_id', '=', $category->id)->pluck('manufacturer');
105   - return view('catalog_detail', compact('items', 'category', 'goods', 'title', 'mf'));
  115 + return view('catalog_detail', compact('items', 'category', 'goods',
  116 + 'title', 'mf', 'articles', 'reviews', 'lookin_good'));
106 117 }
107 118  
108 119 public function good(Good $good) {
109   - return view('good');
  120 + $looking = new Good_Look();
  121 + $looking->goods_id = $good->id;
  122 + $looking->save();
  123 +
  124 + return view('good', compact('good'));
110 125 }
111 126  
112 127 public function simple_good() {
app/Models/Good_Look.php
... ... @@ -0,0 +1,11 @@
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +use Illuminate\Database\Eloquent\Factories\HasFactory;
  6 +use Illuminate\Database\Eloquent\Model;
  7 +
  8 +class Good_Look extends Model
  9 +{
  10 + use HasFactory;
  11 +}
database/migrations/2023_04_12_094609_create_good__looks_table.php
... ... @@ -0,0 +1,32 @@
  1 +<?php
  2 +
  3 +use Illuminate\Database\Migrations\Migration;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Support\Facades\Schema;
  6 +
  7 +return new class extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::create('good__looks', function (Blueprint $table) {
  17 + $table->id();
  18 + $table->integer('goods_id')->nullable(false);
  19 + $table->timestamps();
  20 + });
  21 + }
  22 +
  23 + /**
  24 + * Reverse the migrations.
  25 + *
  26 + * @return void
  27 + */
  28 + public function down()
  29 + {
  30 + Schema::dropIfExists('good__looks');
  31 + }
  32 +};
resources/views/catalog.blade.php
... ... @@ -409,17 +409,21 @@
409 409 </div>
410 410 </section>
411 411  
  412 + @if ($reviews->count())
412 413 <section class="catalog-reviews">
413 414 <div class="container catalog-reviews-container">
414 415 <h2 class="catalog-reviews__title">Отзывы партнеров</h2>
415 416 <div class="swiper swiper-catalog-reviews">
416 417 <div class="swiper-wrapper">
  418 + @foreach($reviews as $review)
417 419 <div class="swiper-slide slide-catalog-reviews">
418   - <img class="slide-catalog-reviews__img" src="./img/catalogPage/cat-rew-1-min.png" alt="">
419   - <h3 class="slide-catalog-reviews__title">Компания “Двери Олимп”</h3>
420   - <p class="slide-catalog-reviews__name">Соколов Алексей</p>
421   - <p class="slide-catalog-reviews__text">Магнитный сверлильный станок Вектор МС 36 или Rotabroach Commando 40?</p>
  420 + <img class="slide-catalog-reviews__img" src="{{ asset(Storage::url($review->image)) }}" alt="">
  421 + <h3 class="slide-catalog-reviews__title">{{$review->company}}</h3>
  422 + <p class="slide-catalog-reviews__name">{{$review->author}}</p>
  423 + <p class="slide-catalog-reviews__text">{{$review->title}}</p>
422 424 </div>
  425 + @endforeach
  426 + <!--
423 427 <div class="swiper-slide slide-catalog-reviews">
424 428 <img class="slide-catalog-reviews__img" src="./img/catalogPage/cat-rew-2-min.png" alt="">
425 429 <h3 class="slide-catalog-reviews__title">Компания “Двери Олимп”</h3>
... ... @@ -437,23 +441,25 @@
437 441 <h3 class="slide-catalog-reviews__title">Компания “Двери Олимп”</h3>
438 442 <p class="slide-catalog-reviews__name">Соколов Алексей</p>
439 443 <p class="slide-catalog-reviews__text">Магнитный сверлильный станок Вектор МС 36 или Rotabroach Commando 40?</p>
440   - </div>
  444 + </div>-->
441 445 </div>
442 446 </div>
443 447 <div class="swiper-button-next swiper-button-next__catalog-reviews">
444 448 <svg class="svg-partners-next">
445   - <use xlink:href="./img/icons.svg#pr-next"></use>
  449 + <use xlink:href="{{ asset('/img/icons.svg#pr-next') }}"></use>
446 450 </svg>
447 451 </div>
448 452 <div class="swiper-button-prev swiper-button-prev__catalog-reviews">
449 453 <svg class="svg-partners-back">
450   - <use xlink:href="./img/icons.svg#pr-prev"></use>
  454 + <use xlink:href="{{ asset('/img/icons.svg#pr-prev')}}"></use>
451 455 </svg>
452 456 </div>
453 457 <a class="catalog-rev-button">Показать все</a>
454 458 </div>
455 459 </section>
  460 + @endif
456 461  
  462 + @if ($lookin_good->count())
457 463 <section class="viewed catalog-viewed">
458 464 <div class="container viewed-container">
459 465 <h2 class="viewed-container__title">
... ... @@ -461,34 +467,35 @@
461 467 </h2>
462 468 <div class="swiper swiper-viewed">
463 469 <div class="swiper-wrapper">
  470 + @foreach ($lookin_good as $look)
464 471 <div class="swiper-slide">
465 472 <div class="viewed__item">
466 473 <div class="catalog__item">
467 474 <div class="swiper swiper-catalog-item">
468 475 <div class="swiper-wrapper">
469 476 <div class="swiper-slide swiper-slide-catalog">
470   - <img class="swiper-slide-catalog-img" src="./img/product/viewed/v-1-min.png"
  477 + <img class="swiper-slide-catalog-img" width="250px" src="{{ asset(Storage::url($look->image)) }}"
471 478 alt="">
472 479 </div>
473   - <div class="swiper-slide swiper-slide-catalog"><img class="swiper-slide-catalog-img"
  480 + <!--<div class="swiper-slide swiper-slide-catalog"><img class="swiper-slide-catalog-img"
474 481 src="../img/product/viewed/v-1-min.png" alt=""></div>
475 482 <div class="swiper-slide swiper-slide-catalog"><img class="swiper-slide-catalog-img"
476   - src="./img/product/viewed/v-1-min.png" alt=""></div>
  483 + src="./img/product/viewed/v-1-min.png" alt=""></div>-->
477 484 </div>
478 485 <div class="swiper-pagination"></div>
479 486 </div>
480 487 </div>
481 488 <div class="viewed__item-info">
482   - <h3 class="viewed__item-title">Установка лазерной
483   - резки GWEIKE</h3>
  489 + <h3 class="viewed__item-title"><a href="{{ route('good', ['good' => $look->id]) }}">{{ $look->title }}</a></h3>
484 490 <div class="viewed__item-bottom">
485   - <p class="viewed__item-price">250 990 ₽</p>
  491 + <p class="viewed__item-price">{{ $look->price }} ₽</p>
486 492 <button class="viewed__item-btn">В каталог</button>
487 493 </div>
488 494 </div>
489 495 </div>
490 496 </div>
491   - <div class="swiper-slide">
  497 + @endforeach
  498 + <!--<div class="swiper-slide">
492 499 <div class="viewed__item">
493 500 <div class="catalog__item">
494 501 <div class="swiper swiper-catalog-item">
... ... @@ -595,7 +602,7 @@
595 602 </div>
596 603 </div>
597 604 </div>
598   - </div>
  605 + </div>-->
599 606 </div>
600 607  
601 608 </div>
... ... @@ -611,4 +618,6 @@
611 618 </div>
612 619 </div>
613 620 </section>
  621 + @endif
  622 +
614 623 @endsection
resources/views/catalog_detail.blade.php
... ... @@ -281,18 +281,19 @@
281 281 </div>
282 282 </section>
283 283  
  284 + @if ($articles->count())
284 285 <section class="catalog-articles">
285 286 <div class="container catalog-articles-container">
286 287 <h2 class="catalog-articles__title">Статьи по разделу</h2>
287 288 <div class="swiper swiper-catalog-articles">
288 289 <div class="swiper-wrapper">
  290 + @foreach($articles as $article)
289 291 <div class="swiper-slide swiper-slide-catalog-articles">
290   - <img class="slide-catalog-articles-img" src="./img/catalogPage/catalog-news-min.png" alt="">
291   - <h3 class="slide-catalog-articles-title">Магнитный сверлильный станок
292   - Вектор МС 36 или Rotabroach
293   - Commando 40?</h3>
  292 + <img class="slide-catalog-articles-img" src="{{asset(Storage::url($article->image))}}" alt="">
  293 + <h3 class="slide-catalog-articles-title">{{$article->title}}</h3>
294 294 </div>
295   - <div class="swiper-slide swiper-slide-catalog-articles">
  295 + @endforeach
  296 + <!--<div class="swiper-slide swiper-slide-catalog-articles">
296 297 <img class="slide-catalog-articles-img" src="./img/catalogPage/catalog-news-min.png" alt="">
297 298 <h3 class="slide-catalog-articles-title">Сверлильный станок PRO 36 AD</h3>
298 299 </div>
... ... @@ -309,22 +310,23 @@
309 310 <h3 class="slide-catalog-articles-title">Магнитный сверлильный станок
310 311 Вектор МС 36 или Rotabroach
311 312 Commando 40?</h3>
312   - </div>
  313 + </div>-->
313 314 </div>
314 315 </div>
315 316 <div class="swiper-button-next swiper-button-next__catalog-articles">
316 317 <svg class="svg-partners-next">
317   - <use xlink:href="./img/icons.svg#pr-next"></use>
  318 + <use xlink:href="{{ asset('/img/icons.svg#pr-next') }}"></use>
318 319 </svg>
319 320 </div>
320 321 <div class="swiper-button-prev swiper-button-prev__catalog-articles">
321 322 <svg class="svg-partners-back">
322   - <use xlink:href="./img/icons.svg#pr-prev"></use>
  323 + <use xlink:href="{{ asset('/img/icons.svg#pr-prev') }}"></use>
323 324 </svg>
324 325 </div>
325 326 <a class="catalog-articles-container__btn" href="#">Показать все</a>
326 327 </div>
327 328 </section>
  329 + @endif
328 330  
329 331 <section class="catalog-info">
330 332 <div class="container">
... ... @@ -402,19 +404,21 @@
402 404 </div>
403 405 </div>
404 406 </section>
405   -
  407 + @if ($reviews->count())
406 408 <section class="catalog-reviews">
407 409 <div class="container catalog-reviews-container">
408 410 <h2 class="catalog-reviews__title">Отзывы партнеров</h2>
409 411 <div class="swiper swiper-catalog-reviews">
410 412 <div class="swiper-wrapper">
  413 + @foreach($reviews as $review)
411 414 <div class="swiper-slide slide-catalog-reviews">
412   - <img class="slide-catalog-reviews__img" src="./img/catalogPage/cat-rew-1-min.png" alt="">
413   - <h3 class="slide-catalog-reviews__title">Компания “Двери Олимп”</h3>
414   - <p class="slide-catalog-reviews__name">Соколов Алексей</p>
415   - <p class="slide-catalog-reviews__text">Магнитный сверлильный станок Вектор МС 36 или Rotabroach Commando 40?</p>
  415 + <img class="slide-catalog-reviews__img" src="{{ asset(Storage::url($review->image)) }}" alt="">
  416 + <h3 class="slide-catalog-reviews__title">{{$review->company}}</h3>
  417 + <p class="slide-catalog-reviews__name">{{$review->author}}</p>
  418 + <p class="slide-catalog-reviews__text">{{$review->title}}</p>
416 419 </div>
417   - <div class="swiper-slide slide-catalog-reviews">
  420 + @endforeach
  421 + <!--<div class="swiper-slide slide-catalog-reviews">
418 422 <img class="slide-catalog-reviews__img" src="./img/catalogPage/cat-rew-2-min.png" alt="">
419 423 <h3 class="slide-catalog-reviews__title">Компания “Двери Олимп”</h3>
420 424 <p class="slide-catalog-reviews__name">Соколов Алексей</p>
... ... @@ -431,23 +435,25 @@
431 435 <h3 class="slide-catalog-reviews__title">Компания “Двери Олимп”</h3>
432 436 <p class="slide-catalog-reviews__name">Соколов Алексей</p>
433 437 <p class="slide-catalog-reviews__text">Магнитный сверлильный станок Вектор МС 36 или Rotabroach Commando 40?</p>
434   - </div>
  438 + </div>--->
435 439 </div>
436 440 </div>
437 441 <div class="swiper-button-next swiper-button-next__catalog-reviews">
438 442 <svg class="svg-partners-next">
439   - <use xlink:href="./img/icons.svg#pr-next"></use>
  443 + <use xlink:href="{{ asset('/img/icons.svg#pr-next') }}"></use>
440 444 </svg>
441 445 </div>
442 446 <div class="swiper-button-prev swiper-button-prev__catalog-reviews">
443 447 <svg class="svg-partners-back">
444   - <use xlink:href="./img/icons.svg#pr-prev"></use>
  448 + <use xlink:href="{{ asset('/img/icons.svg#pr-prev') }}"></use>
445 449 </svg>
446 450 </div>
447 451 <a class="catalog-rev-button">Показать все</a>
448 452 </div>
449 453 </section>
  454 + @endif
450 455  
  456 + @if ($lookin_good->count())
451 457 <section class="viewed catalog-viewed">
452 458 <div class="container viewed-container">
453 459 <h2 class="viewed-container__title">
... ... @@ -455,34 +461,36 @@
455 461 </h2>
456 462 <div class="swiper swiper-viewed">
457 463 <div class="swiper-wrapper">
  464 + @foreach ($lookin_good as $look)
458 465 <div class="swiper-slide">
459 466 <div class="viewed__item">
460 467 <div class="catalog__item">
461 468 <div class="swiper swiper-catalog-item">
462 469 <div class="swiper-wrapper">
463 470 <div class="swiper-slide swiper-slide-catalog">
464   - <img class="swiper-slide-catalog-img" src="./img/product/viewed/v-1-min.png"
465   - alt="">
  471 + <img class="swiper-slide-catalog-img" width="250px" src="{{ asset(Storage::url($look->image)) }}"
  472 + alt=""/>
466 473 </div>
467   - <div class="swiper-slide swiper-slide-catalog"><img class="swiper-slide-catalog-img"
  474 + <!--<div class="swiper-slide swiper-slide-catalog"><img class="swiper-slide-catalog-img"
468 475 src="../img/product/viewed/v-1-min.png" alt=""></div>
469 476 <div class="swiper-slide swiper-slide-catalog"><img class="swiper-slide-catalog-img"
470   - src="./img/product/viewed/v-1-min.png" alt=""></div>
  477 + src="./img/product/viewed/v-1-min.png" alt=""></div>-->
471 478 </div>
  479 +
472 480 <div class="swiper-pagination"></div>
473 481 </div>
474 482 </div>
475 483 <div class="viewed__item-info">
476   - <h3 class="viewed__item-title">Установка лазерной
477   - резки GWEIKE</h3>
  484 + <h3 class="viewed__item-title"><a href="{{ route('good', ['good' => $look->id]) }}">{{ $look->title }}</a></h3>
478 485 <div class="viewed__item-bottom">
479   - <p class="viewed__item-price">250 990 ₽</p>
  486 + <p class="viewed__item-price">{{ $look->price }} ₽</p>
480 487 <button class="viewed__item-btn">В каталог</button>
481 488 </div>
482 489 </div>
483 490 </div>
484 491 </div>
485   - <div class="swiper-slide">
  492 + @endforeach
  493 + <!--<div class="swiper-slide">
486 494 <div class="viewed__item">
487 495 <div class="catalog__item">
488 496 <div class="swiper swiper-catalog-item">
... ... @@ -589,7 +597,7 @@
589 597 </div>
590 598 </div>
591 599 </div>
592   - </div>
  600 + </div>-->
593 601 </div>
594 602  
595 603 </div>
... ... @@ -605,4 +613,5 @@
605 613 </div>
606 614 </div>
607 615 </section>
  616 + @endif
608 617 @endsection
resources/views/good.blade.php
... ... @@ -425,10 +425,10 @@
425 425 <section class="product-cart">
426 426 <div class="container">
427 427 <div class="poduct-cart__links">
428   - <a class="poduct-cart__links-item" href="#">Главная</a><span> /</span>
429   - <a class="poduct-cart__links-item" href="#">Каталог</a><span> /</span>
430   - <a class="poduct-cart__links-item" href="#">Обработка металла</a><span> /</span>
431   - <span class="link_active">Установка лазерной резки GWEIKE, серия LF 6025GH</span>
  428 + <a class="poduct-cart__links-item" href="{{ route('index') }}">Главная</a><span> /</span>
  429 + <a class="poduct-cart__links-item" href="{{ route('catalog') }}">Каталог</a><span> /</span>
  430 + <a class="poduct-cart__links-item" href="{{ route('catalog_detail', ['category' => $good->category->id]) }}">{{ $good->category->name }}</a><span> /</span>
  431 + <span class="link_active">{{ $good->title }}</span>
432 432 </div>
433 433 <div class="cart__wrapper">
434 434 <div class="swiper-product-container">