Jelajahi Sumber

edit input featued

Azam Rezayi 4 tahun lalu
induk
melakukan
928167380b

+ 1 - 0
database/migrations/2020_07_05_045648_create_uploads_table.php

@@ -19,6 +19,7 @@ class CreateUploadsTable extends Migration
             $table->string('path');
             $table->string('extension');
             $table->string('mime_type');
+            $table->enum('type1',['featured_image','gallery_image']);
             $table->morphs('uploadable');
             $table->timestamps();
             $table->softDeletes();

+ 5 - 0
package-lock.json

@@ -5502,6 +5502,11 @@
                 "safe-buffer": "^5.1.2"
             }
         },
+        "mdbootstrap": {
+            "version": "4.19.1",
+            "resolved": "https://registry.npmjs.org/mdbootstrap/-/mdbootstrap-4.19.1.tgz",
+            "integrity": "sha512-vzYd7UQ0H1tyJfDqCYwsAv+sxol/xRkJP/5FMhcdW3ZbN9xUnmWiSPHx3A6ddGxdOQbfJTWxT3G8M+I++Qdk6w=="
+        },
         "mdn-data": {
             "version": "2.0.4",
             "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz",

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
         "@ckeditor/ckeditor5-editor-classic": "^20.0.0",
         "bootstrap-v4-rtl": "^4.4.1-2",
         "croppie": "^2.6.5",
+        "mdbootstrap": "^4.19.1",
         "owl.carousel": "^2.3.4",
         "select2": "^4.0.13"
     }

+ 12 - 3
packages/product/src/Http/Controllers/ProductController.php

@@ -85,10 +85,18 @@ class ProductController extends Controller
         $product->categories()->sync($request->categories);
 
 
-        if ($request->has('photo')) {
-            $file = $request->file('photo');
+        if ($request->has('gallery_image')) {
+            $file = $request->file('gallery_image');
+            $type = 'gallery_image';
             $diskName = 'product';
-            $this->uploader($file, $diskName, $product);
+            $this->uploader($file, $diskName, $product, $type);
+
+        }
+        if ($request->has('featured_image')) {
+            $file = $request->file('featured_image');
+            $type = 'featured_image';
+            $diskName = 'product';
+            $this->uploader($file, $diskName, $product, $type);
 
         }
 
@@ -185,6 +193,7 @@ class ProductController extends Controller
             'mime_type' => $fileMimeType,
             'extension' => $fileExtension,
 
+
         ];
 
 

+ 2 - 1
packages/product/src/Http/Requests/ProductRequest.php

@@ -31,7 +31,8 @@ class ProductRequest extends FormRequest
             'status' => ['required'],
             'discription' => ['required'],
             'categories' => ['required'],
-           'photo' => ['required', 'image', 'mimes:jpeg,jpg,png,gif', 'max:8000'],
+           'gallery_image' => ['required', 'image', 'mimes:jpeg,jpg,png,gif', 'max:8000'],
+           'featured_image' => ['required', 'image', 'mimes:jpeg,jpg,png,gif', 'max:8000'],
 
         ];
 

+ 2 - 1
packages/product/src/Http/Requests/ProductRequestEdit.php

@@ -23,7 +23,7 @@ class ProductRequestEdit extends FormRequest
      */
     public function rules()
     {
-//        dd(request()->all());
+
         return [
             'title' => ['required','max:100'],
             'price' => 'required',
@@ -31,6 +31,7 @@ class ProductRequestEdit extends FormRequest
             'status' => ['required'],
             'discription' => ['required'],
             'categories' => ['required'],
+//            'featured_image' => ['required', 'image', 'mimes:jpeg,jpg,png,gif', 'max:8000'],
 
 
         ];

+ 1 - 1
packages/product/src/Models/Product.php

@@ -12,7 +12,7 @@ class Product extends Model
 {
     use SoftDeletes;
 
-   protected $fillable = ['title', 'discription', 'price', 'creator_id', 'type', 'status', 'sale_price', 'sku', 'slug', 'photo'];
+   protected $fillable = ['title', 'discription', 'price', 'creator_id', 'type', 'status', 'sale_price', 'sku', 'slug', 'gallery_image', 'feature_image'];
 //    protected $guarded = [];
 
     public function user()

+ 2 - 0
packages/product/src/views/index.blade.php

@@ -139,12 +139,14 @@
                                                 </form>
                                             </td>
                                         </tr>
+
                                     @empty
                                         <tr>
                                             <td colspan="5" class="text-center">موردی برای نمایش وجود ندارد.</td>
                                         </tr>
                         @endforelse
                     @endslot
+
                 @endcomponent
                 {{--Paginate section--}}
                 {{ $products->withQueryString()->links() }}

+ 68 - 13
packages/product/src/views/product/create.blade.php

@@ -27,6 +27,29 @@
                 border: 0px;
                 background-color: #fff;
             }
+            .btn-file {
+                position: relative;
+                overflow: hidden;
+            }
+            .btn-file input[type=file] {
+                position: absolute;
+                top: 0;
+                right: 0;
+                min-width: 100%;
+                min-height: 100%;
+                font-size: 100px;
+                text-align: right;
+                filter: alpha(opacity=0);
+                opacity: 0;
+                outline: none;
+                background: white;
+                cursor: inherit;
+                display: block;
+            }
+
+            #img-upload{
+                width: 100%;
+            }
         </style>
     @endslot
     @slot('subject')
@@ -48,7 +71,7 @@
                             @endcomponent
                             <div class="card-body mx-lg-5 px-lg-3">
                                 <form method="POST" action="{{ route('products.store') }}"
-                                      enctype="multipart/form-data">
+                                      class="dropzone" id="dropzone"  enctype="multipart/form-data" >
                                     @csrf
 
                                     <div class="form-group">
@@ -94,12 +117,10 @@
                                                     class="form-control @error('type') is-invalid @enderror" name="type"
                                                     value="{{ old('type') }}" autocomplete="type">
                                                 <option value="">انتخاب کنید</option>
-                                                <option value="0" {{ (old('type') == '0') ? 'selected' : '' }}>ساده
-                                                </option>
-                                                <option value="1" {{ (old('type') == '1') ? 'selected' : '' }}>متغیر
-                                                </option>
-                                                <option value="2" {{ (old('type') == '2') ? 'selected' : '' }}>باندل
-                                                </option>
+                                                <option value="0" {{ (old('type') == '0') ? 'selected' : '' }}>ساده </option>
+                                                <option value="1" {{ (old('type') == '1') ? 'selected' : '' }}>متغیر </option>
+                                                <option value="2" {{ (old('type') == '2') ? 'selected' : '' }}>باندل </option>
+
                                             </select>
 
                                             @error('type')
@@ -193,14 +214,46 @@
                                         @enderror
 
                                     </div>
+                                    <div class="file-upload-wrapper">
+                                        <input type="file" id="input-file-now-custom-2" class="file-upload"
+                                               data-height="500" />
+                                    </div>
+                                    <div class="form-group">
+
+                                        <label for="title">{{ __('product.feature_image') }}</label><i
+                                            class="required">&nbsp; *</i>
+                                        <input type="file" name="file" id="profile-img"
+                                               data-input="thumbnail" data-preview="holder"
+                                               class="form-control photo @error('featured_image') is-invalid  @enderror"
+                                               value="{{old('featured_image')}}" autocomplete="featured_image" autofocus multiple>
+                                        @error('featured_image')
+                                        <span class="invalid-feedback" role="alert">
+                                            <strong>{{ $message }}</strong>
+                                        </span>
+                                        @enderror
+                                        <div class="gallery_files">
+                                            @if( old( 'featured_image' ) )
+                                                <div class="gallery_file_upload mb-2">
+                                                    <div class="file_info">
+                                                        <a class="uploaded_file_thumbnail" target="_blank" href="{{ Storage::url( old( 'featured_image' ) ) }}">
+                                                            <img src="" id="profile-img-tag" width="200px" />
+                                                        </a>
+                                                        <span class="file_name">{{ basename( old( 'featured_image' ) ) }}</span>
+
+                                                    </div>
+                                                    <span class="delete_file"><i class="fas fa-times"></i></span>
+                                                </div>
+                                            @endif
+                                        </div>
+                                    </div>
                                     <div class="form-group">
-                                        <label for="title">{{ __('product.photo') }}</label><i
+                                        <label for="title">{{ __('product.gallery_image') }}</label><i
                                             class="required">&nbsp; *</i>
-                                        <input type="file" name="photo" id="photo"
+                                        <input type="file" name="gallery_image" id="gallery_image"
 
-                                               class="form-control photo @error('photo') is-invalid  @enderror"
-                                               value="{{old('photo')}}" autocomplete="photo" autofocus multiple>
-                                        @error('photo')
+                                               class="form-control photo @error('gallery_image') is-invalid  @enderror"
+                                               value="{{old('gallery_image')}}" autocomplete="gallery_image" autofocus multiple>
+                                        @error('gallery_image')
                                         <span class="invalid-feedback" role="alert">
                                             <strong>{{ $message }}</strong>
                                         </span>
@@ -230,7 +283,9 @@
     @endslot
 
     @slot('script')
-
+        <script>
+        $('.file-upload').file_upload();
+        </script>
     @endslot
 
 @endcomponent

+ 1 - 1
packages/product/src/views/product/edit.blade.php

@@ -157,7 +157,7 @@
 
 
                                         <div class="form-group col-lg-4">
-                                            <label for="status">{{ __('product.status') }}</label></label><i
+                                            <label for="status">{{ __('product.status') }}</label><i
                                                 class="required">&nbsp; *</i>
                                             <select id="status" type="text"
                                                     class="form-control @error('status') is-invalid @enderror"

+ 10 - 0
packages/product/src/views/product/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+</html>

+ 2 - 1
resources/lang/fa/product.php

@@ -9,6 +9,7 @@ return [
   'sku'         => 'sku ',
   'slug'        => 'slug',
   'title'       => 'عنوان',
-  'photo'       => 'عکس محصول',
+  'gallery_image'       => 'عکس محصول',
+  'feature_image'       => 'تصویر شاخص',
 ];
 

+ 1 - 0
resources/sass/app.scss

@@ -20,3 +20,4 @@ body{
 
 
 
+

+ 50 - 0
resources/sass/panel/core/components.scss

@@ -1225,3 +1225,53 @@ input[type="search"]{
         background: rgba(255, 255, 255, 0.8);
     }
 }
+
+
+.gallery_files,
+.attachments{
+    .gallery_file_upload,
+    .attachment_file_upload{
+
+        padding: 1em;
+        border-radius: 3px;
+        direction: ltr;
+        text-align: left;
+        position: relative;
+
+        .delete_file{
+            display: block;
+            position: absolute;
+            top: 1px;
+            right: 1px;
+            width: 24px;
+            height: 24px;
+            text-align: center;
+            line-height: 26px;
+
+            border-radius: 50%;
+
+
+            cursor: pointer;
+
+
+            &:hover{
+
+            }
+        }
+
+        &:nth-child(odd){
+
+        }
+
+        .uploaded_file_thumbnail{
+            img{
+
+                width: 100px;
+                height: 100px;
+                padding: 0.1em;
+                border-radius: 3px;
+                margin-right: 1em;
+            }
+        }
+    }
+}

+ 2 - 0
resources/sass/panel/panel.scss

@@ -72,3 +72,5 @@ table.table-bordered{
 .cursor-pointer {
     cursor: pointer;
 }
+
+

+ 3 - 1
resources/views/panel/layouts/app.blade.php

@@ -17,7 +17,7 @@
 
     <!-- Styles -->
     <link href="{{ mix('css/panel.css') }}" rel="stylesheet">
-{{--    <link href="node_modules/select2/dist/css/select2.min.css" rel="stylesheet" />--}}
+
 
     @yield('style')
 
@@ -34,7 +34,9 @@
     </div>
 
     <!-- Scripts -->
+
     <script src="{{ mix('js/panel.js') }}"></script>
+
     @include('sweet::alert')
     @yield('script')