ソースを参照

make tabale upload

Azam Rezayi 4 年 前
コミット
502d5acc38

+ 2 - 2
app/Models/Upload.php

@@ -8,8 +8,8 @@ use Packages\Product\Models\Product;
 
 class Upload extends Model
 {
-    protected $fillable = ['photo', 'path', 'mime_type'];
-    public function uploadables()
+    protected $fillable = ['name', 'path', 'mime_type', 'extension', 'uploadable_type', 'uploadable_id'];
+    public function uploadable()
     {
         return $this->morphTo();
     }

+ 1 - 0
composer.json

@@ -17,6 +17,7 @@
         "laravel/tinker": "^2.0",
         "laravel/ui": "^2.0",
         "league/flysystem-cached-adapter": "~1.0",
+        "morilog/jalali": "^3.1",
         "santigarcor/laratrust": "^6.0",
         "uxweb/sweet-alert": "^2.0",
         "va/cutlet-recaptcha": "^1.1"

+ 118 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "978622f37b7dcfc6d245cbfd8a18d3a9",
+    "content-hash": "fa961afffd973f162bb982d36c8c6031",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -59,6 +59,68 @@
             "time": "2019-12-24T22:41:47+00:00"
         },
         {
+            "name": "beberlei/assert",
+            "version": "v3.2.7",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/beberlei/assert.git",
+                "reference": "d63a6943fc4fd1a2aedb65994e3548715105abcf"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/beberlei/assert/zipball/d63a6943fc4fd1a2aedb65994e3548715105abcf",
+                "reference": "d63a6943fc4fd1a2aedb65994e3548715105abcf",
+                "shasum": ""
+            },
+            "require": {
+                "ext-ctype": "*",
+                "ext-json": "*",
+                "ext-mbstring": "*",
+                "ext-simplexml": "*",
+                "php": "^7"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "*",
+                "phpstan/phpstan-shim": "*",
+                "phpunit/phpunit": ">=6.0.0 <8"
+            },
+            "suggest": {
+                "ext-intl": "Needed to allow Assertion::count(), Assertion::isCountable(), Assertion::minCount(), and Assertion::maxCount() to operate on ResourceBundles"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Assert\\": "lib/Assert"
+                },
+                "files": [
+                    "lib/Assert/functions.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-2-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Benjamin Eberlei",
+                    "email": "kontakt@beberlei.de",
+                    "role": "Lead Developer"
+                },
+                {
+                    "name": "Richard Quadling",
+                    "email": "rquadling@gmail.com",
+                    "role": "Collaborator"
+                }
+            ],
+            "description": "Thin assertion library for input validation in business models.",
+            "keywords": [
+                "assert",
+                "assertion",
+                "validation"
+            ],
+            "time": "2019-12-19T17:51:41+00:00"
+        },
+        {
             "name": "brick/math",
             "version": "0.8.15",
             "source": {
@@ -1335,6 +1397,61 @@
             "time": "2019-12-20T14:22:59+00:00"
         },
         {
+            "name": "morilog/jalali",
+            "version": "v3.1.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/morilog/jalali.git",
+                "reference": "ae040b5659c04933f8d7423f1fabaa1dd168d62b"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/morilog/jalali/zipball/ae040b5659c04933f8d7423f1fabaa1dd168d62b",
+                "reference": "ae040b5659c04933f8d7423f1fabaa1dd168d62b",
+                "shasum": ""
+            },
+            "require": {
+                "beberlei/assert": "3.*",
+                "nesbot/carbon": "^1.21 || ^2.0",
+                "php": "^7.0 | ^7.1 | ^7.2"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Morilog\\Jalali\\": "src"
+                },
+                "files": [
+                    "src/helpers.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Milad Rey",
+                    "email": "miladr@gmail.com"
+                },
+                {
+                    "name": "Morteza Parvini",
+                    "email": "m.parvini@outlook.com"
+                }
+            ],
+            "description": "This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.",
+            "keywords": [
+                "Jalali",
+                "date",
+                "datetime",
+                "laravel",
+                "morilog"
+            ],
+            "time": "2019-12-16T06:24:41+00:00"
+        },
+        {
             "name": "nesbot/carbon",
             "version": "2.33.0",
             "source": {

+ 4 - 0
config/app.php

@@ -162,10 +162,13 @@ return [
         Illuminate\Validation\ValidationServiceProvider::class,
         Illuminate\View\ViewServiceProvider::class,
 
+
+
         /*
          * Package Service Providers...
          */
          Packages\Product\ProductServiceProvider::class,
+
         /*
          * Application Service Providers...
          */
@@ -228,6 +231,7 @@ return [
         'Validator' => Illuminate\Support\Facades\Validator::class,
         'View' => Illuminate\Support\Facades\View::class,
 
+
     ],
 
 ];

+ 0 - 32
database/migrations/2020_07_04_110256_create_uploadables_table.php

@@ -1,32 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-class CreateUploadablesTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('uploadables', function (Blueprint $table) {
-            $table->integer('upload_id');
-            $table->integer('uploadable_id');
-            $table->string('uploadable_type');
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::dropIfExists('uploadables');
-    }
-}

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

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateUploadsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('uploads', function (Blueprint $table) {
+            $table->id();
+            $table->string('name');
+            $table->string('path');
+            $table->string('extension');
+            $table->string('mime_type');
+            $table->morphs('uploadable');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('uploads');
+    }
+}

+ 54 - 0
package-lock.json

@@ -952,6 +952,55 @@
                 "to-fast-properties": "^2.0.0"
             }
         },
+        "@ckeditor/ckeditor5-core": {
+            "version": "20.0.0",
+            "resolved": "https://registry.npmjs.org/@ckeditor/ckeditor5-core/-/ckeditor5-core-20.0.0.tgz",
+            "integrity": "sha512-63WA8178ac7MVwDEgNKGJQxXqBeKzoLLkE7Hg9AEz3IMCeo6f1vM9Ac27Rd8mRXWsulinj+h2k/JI2d3WLKyeg==",
+            "requires": {
+                "@ckeditor/ckeditor5-engine": "^20.0.0",
+                "@ckeditor/ckeditor5-utils": "^20.0.0",
+                "lodash-es": "^4.17.15"
+            }
+        },
+        "@ckeditor/ckeditor5-editor-classic": {
+            "version": "20.0.0",
+            "resolved": "https://registry.npmjs.org/@ckeditor/ckeditor5-editor-classic/-/ckeditor5-editor-classic-20.0.0.tgz",
+            "integrity": "sha512-etKQSKTk0Rry6sclD15Vc9dptRwH+XYLeWBTFsMz61SSP5fGPjP08yFKSFR4eXXBC2zl+unaXGhsnZB5KptLwA==",
+            "requires": {
+                "@ckeditor/ckeditor5-core": "^20.0.0",
+                "@ckeditor/ckeditor5-engine": "^20.0.0",
+                "@ckeditor/ckeditor5-ui": "^20.0.0",
+                "@ckeditor/ckeditor5-utils": "^20.0.0",
+                "lodash-es": "^4.17.15"
+            }
+        },
+        "@ckeditor/ckeditor5-engine": {
+            "version": "20.0.0",
+            "resolved": "https://registry.npmjs.org/@ckeditor/ckeditor5-engine/-/ckeditor5-engine-20.0.0.tgz",
+            "integrity": "sha512-ax+AvD/c/VIjqhQQWwl3KZc7+C2xYprJsNJmdN6NfiJTb9jM45/kdDum7RcuJ4BsYMT7el/D14JQ+uZTE/2O8g==",
+            "requires": {
+                "@ckeditor/ckeditor5-utils": "^20.0.0",
+                "lodash-es": "^4.17.15"
+            }
+        },
+        "@ckeditor/ckeditor5-ui": {
+            "version": "20.0.0",
+            "resolved": "https://registry.npmjs.org/@ckeditor/ckeditor5-ui/-/ckeditor5-ui-20.0.0.tgz",
+            "integrity": "sha512-xjxJdPoDu7SZDkT1XkpAE2nB3qKca7aUVNPRtn9Skq6zIB+64wuySv2CaRTJpG9fSJhaFXmt7b7TXjrjS2X0Ow==",
+            "requires": {
+                "@ckeditor/ckeditor5-core": "^20.0.0",
+                "@ckeditor/ckeditor5-utils": "^20.0.0",
+                "lodash-es": "^4.17.15"
+            }
+        },
+        "@ckeditor/ckeditor5-utils": {
+            "version": "20.0.0",
+            "resolved": "https://registry.npmjs.org/@ckeditor/ckeditor5-utils/-/ckeditor5-utils-20.0.0.tgz",
+            "integrity": "sha512-BAzI5Ld4ixbumr+B/MtCob9cqgz+K6eQowILx3GRROEHWsA6JIvPOHHxQJoa+pyPPeRrPqg2u8LQvPKiJsUvww==",
+            "requires": {
+                "lodash-es": "^4.17.15"
+            }
+        },
         "@mrmlnc/readdir-enhanced": {
             "version": "2.2.1",
             "resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
@@ -5342,6 +5391,11 @@
             "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
             "dev": true
         },
+        "lodash-es": {
+            "version": "4.17.15",
+            "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.15.tgz",
+            "integrity": "sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ=="
+        },
         "lodash.memoize": {
             "version": "4.1.2",
             "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
         "vue-template-compiler": "^2.6.11"
     },
     "dependencies": {
+        "@ckeditor/ckeditor5-editor-classic": "^20.0.0",
         "bootstrap-v4-rtl": "^4.4.1-2",
         "croppie": "^2.6.5",
         "owl.carousel": "^2.3.4",

+ 21 - 19
packages/product/src/Http/Controllers/ProductController.php

@@ -57,14 +57,14 @@ class ProductController extends Controller
 
 // *********************************************************save products ******************
 
-    public function store(ProductRequest $request)
+    public function store(ProductRequest $request )
     {
 
         $request->merge([
             'price' => preg_replace('/[^0-9]+/', '', $request->price),
             'sale_price' => preg_replace('/[^0-9]+/', '', $request->sale_price),
         ]);
-//        $data = array_merge($request->except('categories'), ['creator_id' => auth()->user()->id]);
+
 
         $data = [
             'title' => $request->title,
@@ -79,28 +79,30 @@ class ProductController extends Controller
         ];
 
         $product = Product::create($data);
-
-       if($request->hasFile('photo')){
-            $file = $request-> file('photo');
-            $fileName = 'product-file-' . time() . '.' . $file->getClientOriginalName();
-           $upload = $file->storeAs('photos' , $fileName , 'product');
-           $product= Upload::create([
-            'photo' => $upload,
-            'path' => 'App\Upload',
-            'mime_type' => 'image',
-
-
-
-        ]);
-
+        $afterDiskRoot = '/' . jdate()->format('Y') . '/' . jdate('m');
+        $diskName = 'product';
+        $fileMime = $file->getClientMimeType();
+        $fileExtension = $file->getClientOriginalExtension();
+        $fileName = 'product-file-' . '_' . $file->getClientOriginalName();
+        $filePath = storage_path('app/product/' . $diskName . $afterDiskRoot . '/' . $fileName);
+        if (File::exists($filePath)) {
+
+            $fileName = time() . '_' . $fileName;
         }
+        $dataUpload = [
+         'name' => $fileName,
+         'extension' => $fileExtension,
+         'path' => $filePath,
+         'mime_type' => $fileMime,
 
+        ];
+        $product->upload->create($dataUpload);
 
         $product->categories()->sync($request->categories);
-       $product->upload()->sync($request->upload);
-        dd($product);
+        $product->upload()->sync($request->upload);
+        dd($request->all());
         $msg = 'ذخیره محصول با موفقیت انجام شد ';
-        return redirect(route('products.edit', $product->id),compact('upload'))->with('success', $msg);
+        return redirect(route('products.edit', $product->id), compact('upload'))->with('success', $msg);
     }
 
     // ******************************************************edit page product*********************************************

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

@@ -30,8 +30,8 @@ class ProductRequest extends FormRequest
             'type' => ['required'],
             'status' => ['required'],
             'discription' => ['required'],
-            "categories" => ['required'],
-            "photo" => ['required','file','image','mimes:jpeg,npg,gif,webp,jfif','max:2048'],
+            'categories' => ['required'],
+            'photo' => ['required','file','image','mimes:jpeg,npg,gif,webp,jfif','max:2048'],
 
         ];
 

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

@@ -27,7 +27,7 @@ class Product extends Model
     }
     public function upload()
     {
-        return $this->morphToMany(Upload::class, 'uploadables');
+        return $this->morphToMany(Upload::class, 'uploadable');
     }
     public function getTypeAttribute($value)
     {

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

@@ -154,7 +154,7 @@
                                         <label for="discription">{{ __('product.discription') }}</label></label><i
                                             class="required">&nbsp; *</i>
                                         <textarea id="discription" type="text"
-                                                  class="form-control @error('discription') is-invalid @enderror"
+                                                  class="form-control  @error('discription') is-invalid @enderror"
                                                   name="discription"
 
                                                   autocomplete="discription"

+ 30 - 0
resources/js/app.js

@@ -7,3 +7,33 @@ require('owl.carousel');
 require('croppie/croppie');
 window.select2 = require('select2/dist/js/select2.js');
 
+// window.ClassicEditor = require('@ckeditor/ckeditor5-build-classic');
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// let Highcharts = window.Highcharts = require(highlight);
+// require('highlight/modules/exporting')(Highcharts);
+
+