Pārlūkot izejas kodu

增加删除模板

duqinya 6 gadi atpakaļ
vecāks
revīzija
b0bd71d61c

+ 3 - 1
app/Models/CmsContentTemplate.php

@@ -1,9 +1,11 @@
 <?php
 
 namespace App\Models;
-
+use Illuminate\Database\Eloquent\SoftDeletes;
 class CmsContentTemplate extends BaseModel
 {
+    use SoftDeletes;
+    protected $dates = ['deleted_at'];
     protected  $table = 'cms_content_template';
 
 

+ 0 - 2
app/Repositories/CmsContentTemplateRepository.php

@@ -18,8 +18,6 @@ class CmsContentTemplateRepository {
         $where = [];
 //        if (isset($request['is_open'])){
 //            $where[] = ['is_open','=',$request['is_open']];
-//            return $this->cmsContentTemplate->where($where)->orderBy('id', 'asc')->paginate($perPage);
-//
 //        }
         if (isset($request['city_id'])){
             $where[] = [

+ 5 - 5
app/Repositories/CmsContentTemplateSetRepository.php

@@ -232,15 +232,15 @@ class CmsContentTemplateSetRepository {
             }
         }
 
-        $update_open = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->update(['is_open' => 0]);
-        if (!$update_open) {
-            throw new HttpException(500, '修改失败,请重试');
-        }
-
         $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['is_open' => 1]);
         if (!$update_tpl) {
             throw new HttpException(500, '修改失败,请重试');
         }
+        $update_open = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->delete();
+        if (!$update_open) {
+            throw new HttpException(500, '删除失败,请重试');
+        }
+
         $update_open = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->update(['status' => 0]);
 
         if (!$update_open) {

+ 32 - 0
database/migrations/2019_05_22_015511_add_delete_to_cms_content_template_table.php

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