Bläddra i källkod

create table rlation product and category

azam 4 år sedan
förälder
incheckning
99ab54a181

+ 1 - 1
app/User.php

@@ -79,6 +79,6 @@ class User extends Authenticatable implements MustVerifyEmail
     }
     public function product()
     {
-        return $this->belongsTo(User::class);
+        return $this->hasMany(Product::class,'creator_id', 'id');
     }
 }

+ 31 - 0
database/migrations/2020_06_21_112600_create_product_category.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateProductCategory extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('product_category', function (Blueprint $table) {
+            $table->id();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('product_category');
+    }
+}

+ 1 - 1
packages/product/src/Http/Controllers/ProductController.php

@@ -43,7 +43,7 @@ class ProductController extends Controller
             'type' => 'required',
 
         ]);
-        $data = array_merge($request->all(),['creator_id'=>auth()->user()->id]);
+        $data = array_merge($request->all(),['creator_id' => auth()->user()->name]);
         $product = Product::create($data);
 
 

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

@@ -14,7 +14,7 @@ class Product extends Model
 
     public function user()
     {
-        return $this->belongsTo(User::class);
+        return $this->belongsTo(User::class, 'creator_id', 'id');
     }
 
     public function category()

+ 1 - 1
packages/product/src/database/migrations/2020_06_20_171824_create_categories_table.php

@@ -18,7 +18,7 @@ class CreateCategoriesTable extends Migration
             $table->string('title');
             $table->string('discription');
             $table->string('creator_id');
-            $table->string('slug')->unique();
+            $table->string('slug')->unique()->nullable();
             $table->string('category_type');
             $table->integer('parent')->default(0);
             $table->timestamps();

+ 12 - 7
packages/product/src/views/categories/create.blade.php

@@ -10,6 +10,12 @@
 
                 background-color: hsl(315, 22%, 86%);
             }
+            .required{
+                color:red;
+            }
+            .py-5 {
+                padding-top: 0 !important;
+            }
         </style>
     @endslot
     @slot('subject')
@@ -24,7 +30,7 @@
         <div class="auth-background h-auto py-5">
             <div class="container py-5">
                 <div class="row align-items-center">
-                    <div class="col-lg-8 col-md-10 mx-auto">
+                    <div class="col-lg-11 col-md-11 mx-auto">
                         <div class="card">
                             <div class="card-header"><strong>{{ __('ثبت دسته بندی جدید') }}</strong></div>
 
@@ -33,7 +39,7 @@
                                     @csrf
 
                                     <div class="form-group">
-                                        <label for="title">{{ __('نام دسته جدید') }}</label>
+                                        <label for="title">{{ __('نام دسته ') }}</label><i class="required">&nbsp; *</i>
                                         <input id="title" type="text"
                                                class="form-control @error('title') is-invalid @enderror" name="title"
                                                value="{{ old('title') }}" required autocomplete="title" autofocus>
@@ -47,7 +53,7 @@
                                     </div>
 
                                     <div class="form-group">
-                                        <label for="slug">  {{ __('نام مستعار دسته بندی  ') }}</label>
+                                        <label for="slug">  {{ __('slug  ') }}</label>
                                         <input id="slug" type="text"
                                                class="form-control @error('slug') is-invalid @enderror"
                                                name="slug" value="{{ old('slug') }}" required
@@ -61,7 +67,7 @@
 
                                     </div>
                                     <div class="form-group">
-                                        <label for="parent">  {{ __('کد  دسته بندی  ') }}</label>
+                                        <label for="parent">  {{ __('parent  ') }}</label>
                                         <input id="parent" type="text"
                                                class="form-control @error('parent') is-invalid @enderror"
                                                name="parent" value="{{ old('parent') }}" required
@@ -76,7 +82,7 @@
                                     </div>
 
                                     <div class="form-group">
-                                        <label for="category_type">{{ __(' نوع دسته بندی') }}</label>
+                                        <label for="category_type">{{ __(' نوع دسته ') }}</label><i class="required">&nbsp; *</i>
                                         <select id="category_type" type="text"
                                                 class="form-control @error('category_type') is-invalid @enderror"
                                                 name="category_type"
@@ -94,11 +100,10 @@
 
 
                                     <div class="form-group">
-                                        <label for="discription">{{ __(' توضیحات  دسته بندی') }}</label>
+                                        <label for="discription">{{ __(' توضیحات دسته ') }}</label>
                                         <textarea id="discription" type="text"
                                                   class="form-control @error('discription') is-invalid @enderror"
                                                   name="discription"
-                                                  required
                                                   autocomplete="discription">{{ old('discription') }}</textarea>
 
                                         @error('discription')

+ 1 - 1
packages/product/src/views/categories/index.blade.php

@@ -42,7 +42,7 @@
                                     <th>نام دسته بندی</th>
                                     <th>slug</th>
                                     <th>نوع دسته بندی</th>
-                                    <th> کد دسته بندی</th>
+                                    <th> parent</th>
                                     <th>توضیحات دسته بندی</th>
                                     <th> اضافه کننده دسته بندی</th>
                                     <th> مدیریت</th>

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

@@ -42,7 +42,7 @@
                                     <th>شماره</th>
                                     <th>نام</th>
                                     <th>slug</th>
-                                    <th> کد محصول</th>
+                                    <th> sku</th>
                                     <th>قیمت</th>
                                     <th>قیمت فروش</th>
                                     <th> نویسنده</th>
@@ -76,7 +76,8 @@
                                             {{$product->sale_price}}
                                         </td>
                                         <td>
-                                            {{--                                            {{$product->user->username}}--}}
+{{--                                   {{$product->user->id}}--}}
+
                                         </td>
                                         <td>
                                             {{$product->status}}