فهرست منبع

added images to catalog

Alexander Musikhin 7 ماه پیش
والد
کامیت
c6a0ea784d
3فایلهای تغییر یافته به همراه29 افزوده شده و 5 حذف شده
  1. 1 0
      app/Http/Controllers/ProductController.php
  2. 23 3
      app/Models/Product.php
  3. 5 2
      resources/views/partials/table.blade.php

+ 1 - 0
app/Http/Controllers/ProductController.php

@@ -19,6 +19,7 @@ class ProductController extends Controller
         'title'     => 'Каталог',
         'id'        => 'products',
         'header'    => [
+            'image'                     => 'Картинка',
             'id'                        => 'ID',
             'article'                   => 'Артикул',
             'nomenclature_number'       => 'Номер номенклатуры',

+ 23 - 3
app/Models/Product.php

@@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Database\Eloquent\Relations\HasOne;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Storage;
 
 #[ScopedBy([YearScope::class])]
 class Product extends Model
@@ -49,8 +50,16 @@ class Product extends Model
         });
     }
 
-    protected $appends = ['product_price', 'installation_price', 'total_price',
-                          'product_price_txt', 'installation_price_txt', 'total_price_txt',];
+    protected $appends = [
+        'product_price',
+        'installation_price',
+        'total_price',
+        'product_price_txt',
+        'installation_price_txt',
+        'total_price_txt',
+        'image'
+    ];
+
     protected function productPrice(): Attribute
     {
         return Attribute::make(
@@ -102,7 +111,6 @@ class Product extends Model
     {
         return Attribute::make(
             get: fn($value) =>  $this->article . ', №' . $this->nomenclature_number,
-//            get: fn($value) => (string) $this->name_tz . ' (арт.' . $this->article . ', №' . $this->nomenclature_number . ', ' . $this->year . 'г, ' . $this->product_price_txt . ')',
         );
     }
 
@@ -134,6 +142,18 @@ class Product extends Model
         return false;
     }
 
+    public function image(): Attribute
+    {
+        if(file_exists(public_path() . '/images/main/' . $this->article . '.0000.0000.jpg')) {
+
+            $path =  url('/images/main/' . $this->article . '.0000.0000.jpg');
+        } else {
+            $path =  '';
+        }
+        return Attribute::make(
+            get: fn() =>  $path,
+        );
+    }
 
 
 }

+ 5 - 2
resources/views/partials/table.blade.php

@@ -49,11 +49,10 @@
             <tr>
                 @foreach($header as $headerName => $headerTitle)
                     <td class="column_{{$headerName}}"
-                        @isset($routeName) onclick="location.href='{{ route($routeName, $string->id) }}'" @endisset>
+                        @if(isset($routeName) && !in_array($headerName, ['image'])) onclick="location.href='{{ route($routeName, $string->id) }}'" @endif>
                         @if(str_contains($headerName, '-'))
                             @php
                                 list($rel, $field) = explode('-', $headerName);
-//                                var_dump($string->$rel);die();
                             @endphp
                             @if(isset($string->$rel->$field))
                                 @if(str_ends_with($field, '_id'))
@@ -81,6 +80,10 @@
                             {!! $string->$relation?->name; !!}
                         @elseif(str_ends_with($headerName, '_date') && ($string->$headerName))
                             {{ \App\Helpers\DateHelper::getHumanDate($string->$headerName, true) }}
+                        @elseif($headerName == 'image' && $string->$headerName)
+                            <a href="{{ $string->$headerName }}" data-toggle="lightbox" data-gallery="photos" data-size="fullscreen">
+                                <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail" style="max-height: 150px" >
+                            </a>
                         @else
                             {!! $string->$headerName !!}
                         @endif