فهرست منبع

Create migration draft and attachment

Azam Rezayi 4 سال پیش
والد
کامیت
e1761525b2

+ 85 - 0
packages/product/src/Http/Controllers/AttachmentController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Attachment;
+use Illuminate\Http\Request;
+
+class AttachmentController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Attachment  $attachment
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Attachment $attachment)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Attachment  $attachment
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Attachment $attachment)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Attachment  $attachment
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Attachment $attachment)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Attachment  $attachment
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Attachment $attachment)
+    {
+        //
+    }
+}

+ 85 - 0
packages/product/src/Http/Controllers/DraftController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Draft;
+use Illuminate\Http\Request;
+
+class DraftController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Draft  $draft
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Draft $draft)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Draft  $draft
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Draft $draft)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Draft  $draft
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Draft $draft)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Draft  $draft
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Draft $draft)
+    {
+        //
+    }
+}

+ 8 - 40
packages/product/src/Http/Controllers/ProductController.php

@@ -66,13 +66,6 @@ class ProductController extends Controller
 
     public function store(ProductRequest $request)
     {
-        /*foreach ($request->file('gallery_image') as $item) {
-            echo '<pre>';
-            print_r($item);
-            echo '</pre>';
-        }
-        die();*/
-
         $request->merge([
             'price' => preg_replace('/[^0-9]+/', '', $request->price),
             'sale_price' => preg_replace('/[^0-9]+/', '', $request->sale_price),
@@ -340,49 +333,24 @@ class ProductController extends Controller
         }
 
     }
-    public function myformProduct(Request $request)
-    {
-        $messages = [
-            'title.required'   => 'وارد کردن نام الزامی است!',
-            'price.required'    => 'وارد کردن قیمت الزامی است!',
-            'slug.required'        => 'وارد کردن slug الزامی است!',
-            'type.required'           => 'وارد کردن نوع الزامی است!',
-            'status.required'      => 'وارد کردن وضعیت الزامی است!',
-            'discription.required'      => 'وارد کردن توضیحات الزامی است!',
-            'categories.required'      => 'وارد کردن دسته بندی الزامی است!',
-            'featured_image.required'      => 'وارد کردن تصوی شاخص الزامی است!',
 
-        ];
-        $validator = Validator::make($request->all(), [
-            'title'    => 'required',
-            'price'     => 'required',
-            'slug'         => 'required',
-            'type'       => 'required',
-            'status'       => 'required',
-            'discription'       => 'required',
-            'categories'       => 'required',
-            'featured_image'       => 'required',
-
-        ], $messages);
-
-        if ($validator->passes()) {
-            return response()->json(['success'=>'Added new records.']);
-        }
-        return response()->json(['error'=>$validator->errors()->all()]);
-    }
-    public function SaveFormProductByAjax()
+    public function SaveFormProductByAjax(Request $request)
     {
         $title = $this->input->post('title');
         $price = $this->input->post('price');
         $slug = $this->input->post('slug');
         $type= $this->input->post('type');
+        $ReleaseStatus = $this->input->post('ReleaseStatus');
         $status = $this->input->post('status');
         $discription = $this->input->post('discription');
         $categories = $this->input->post('categories');
         $featured_image = $this->input->post('featured_image');
 
-        $data=array('title'=>$title,"price"=>$price,"slug"=>$slug,"type"=>$type,"status"=>$status,"discription"=>$discription,"categories"=>$categories,"featured_image"=>$featured_image);
-        DB::table('enquiry')->insert($data);
-        echo "Record inserted successfully";
+        $data=array('title' => $title,"price" =>  $price,"slug" => $slug,"type" => $type,"status" => $status,"discription" => $discription,"categories" => $categories,"featured_image" => $featured_image,"ReleaseStatus" => $ReleaseStatus);
+       $prouduct = Product::update($data);
+        return $prouduct->with('success', 'اطلاعات با موفقیت ثبت شد .') ;
+
+
+
     }
 }

+ 10 - 0
packages/product/src/Models/Attachment.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace Packages\Product\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Attachment extends Model
+{
+    //
+}

+ 10 - 0
packages/product/src/Models/Draft.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace Packages\Product\Models;
+use Packages\Product\Traits\Attachments;
+use Illuminate\Database\Eloquent\Model;
+
+class Draft extends Model
+{
+    use Attachments;
+}

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

@@ -21,7 +21,7 @@ class CreateProductsTable extends Migration
             $table->string('price');
             $table->string('sale_price')->nullable();
             $table->string('creator_id');
-            $table->enum('ReleaseStatus',['draft','pending','published']);
+            $table->enum('ReleaseStatus',['draft','pending','published'])->default('pending');
             $table->string('type')->default("0");
             $table->string('sku')->unique()->nullable();
             $table->string('status')->default("0");

+ 33 - 0
packages/product/src/database/migrations/2020_08_01_075245_create_attachments_table.php

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

+ 32 - 0
packages/product/src/database/migrations/2020_08_01_075319_create_drafts_table.php

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

+ 2 - 4
packages/product/src/routes/web.php

@@ -20,10 +20,8 @@ Route::group([
 });
 
 
-//Route::get('my-form','ProductController@myformProduct');
-//
-//Route::post('my-form','ProductController@myformProduct');
-Route::post('SaveFormProductByAjax','UserController@SaveFormProductByAjax');
+
+Route::post('/product/SaveFormProductByAjax','ProductControllerController@SaveFormProductByAjax')->name('SaveFormProductByAjax');
 
 
 

+ 63 - 53
packages/product/src/views/product/create.blade.php

@@ -187,7 +187,7 @@
                                     </div>
                                     <div class="form-group mb-0">
                                         <div class="">
-                                            <button type="submit" class="btn btn-primary">
+                                            <button type="submit" class="btn btn-primary" >
                                                 {{ __('ثبت محصول') }}
                                             </button>
                                             <a href="{{ route('products.index') }}" type="button" class="btn btn-warning" > انصراف</a>
@@ -207,58 +207,68 @@
 
     @slot('script')
         <script>
-            // $(document).ready(function() {
-            //         $("#DraftProduct").on('click', function(e) {
-            //             var getUrl = window.location;
-            //             var base_url = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
-            //                 e.preventDefault();
-            //                 var message = $('.message').val();
-            //                 if (message === '') {
-            //                     alert("لطفا پارامتر ارسالی را وارد کنید");
-            //                 }else{
-            //                     $.ajax({
-            //                         type: "POST",
-            //                         url: base_url + "/product/store",
-            //                         data: '{message: "' + $('.message').val() + '" }',
-            //                         contentType: "application/json; charset=utf-8",
-            //                         dataType: "json",
-            //                         success: function(response) {
-            //                             if (response.Ajax) {
-            //                                 alert(response.msg);
-            //                             } else {
-            //                                 alert("این متن برای تست  می باشد");
-            //                             }
-            //                         },
-            //                         error: function(response) {
-            //                             alert("مشکلی در اجرای برنامه به وجود آمده ");
-            //                         }
-            //                     });
-            //                 }
-            //             });
-            // });
-            $(document).ready(function(){
-                $("#DraftProduct").click(function(e){
-                    var getUrl = window.location;
-                               var base_url = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
-                    e.preventDefault();
-                    title = $("#title").val();
-                    price = $("#price").val();
-                    slug = $("#slug").val();
-                    type = $("#type").val();
-                    status = $("#status").val();
-                    discription = $("#discription").val();
-                    categories = $("#categories").val();
-                    featured_image = $("#featured_image").val();
-                    $.ajax({
-                        type:"POST",
-                        data:{"title":title,"price":price,"slug":slug,"type":type,"status":status,"discription":discription,"categories":categories,"featured_image":featured_image},
-                        url:base_url +"/product/SaveFormProductByAjax",
-                        success:function(data){
-                            $("#success").html(data);
-                        }
-                    });
-                });
-            });
+                    $("#DraftProduct").on('keypress', function(e) {
+                         // alert('ssalam');
+                        var getUrl = window.location;
+                        var base_url = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
+                            e.preventDefault();
+
+                                title = $("#title").val();
+                                price = $("#price").val();
+                                slug = $("#slug").val();
+                                type = $("#type").val();
+                                status = $("#status").val();
+                                ReleaseStatus = $("#ReleaseStatus").val();
+                                discription = $("#discription").val();
+                                categories = $("#categories").val();
+                               featured_image = $("#featured_image").val();
+
+                            if (title === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                            if (price === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                            if (slug === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                             if (type  === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                             if (status  ==='') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                             if (discription  === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                             if (categories  === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }
+                             if (featured_image === '') {
+                                alert("لطفا پارامتر ارسالی را وارد کنید");
+                            }else{
+                                $.ajax({
+                                    method: "POST",
+                                    url: base_url + "/product/SaveFormProductByAjax",
+                                     data:{"title":title,"price":price,"slug":slug,"type":type,"status":status,"discription":discription,"categories":categories,"featured_image":featured_image},
+                                    // contentType: "application/json; charset=utf-8",
+                                    dataType: "json",
+                                    success: function(response) {
+                                        if (response.Ajax) {
+                                            alert(response.msg);
+                                        } else {
+                                            alert("این متن برای تست  می باشد");
+                                        }
+                                    },
+                                    error: function(response) {
+                                        alert("مشکلی در اجرای برنامه به وجود آمده ");
+                                    }
+                                });
+                            }
+                        timeout: 10000
+                        });
+
+
         </script>
     @endslot