浏览代码

Edit category name

1day2die 2 年之前
父节点
当前提交
9420231b58

+ 15 - 18
app/Http/Controllers/Moderation/TicketCategoryController.php

@@ -16,8 +16,8 @@ class TicketCategoryController extends Controller
      */
     public function index()
     {
-
-        return view('moderator.ticket.category');
+        $categories = TicketCategory::all();
+        return view('moderator.ticket.category')->with("categories",$categories);
     }
 
     /**
@@ -38,28 +38,26 @@ class TicketCategoryController extends Controller
         return redirect(route("moderator.ticket.category.index"))->with("success",__("Category created"));
     }
 
-
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param  int  $id
-     * @return \Illuminate\Http\Response
-     */
-    public function edit($id)
-    {
-        //
-    }
-
     /**
      * Update the specified resource in storage.
      *
      * @param  \Illuminate\Http\Request  $request
-     * @param  int  $id
      * @return \Illuminate\Http\Response
      */
-    public function update(Request $request, $id)
+    public function update(Request $request)
     {
-        //
+        $request->validate([
+            'category' => 'required|int',
+            'name' => 'required|string|max:191',
+        ]);
+
+        $category = TicketCategory::where("id",$request->category)->firstOrFail();
+
+        $category->name = $request->name;
+        $category->save();
+
+        return redirect()->back()->with("success",__("Category name updated"));
+
     }
 
     /**
@@ -103,7 +101,6 @@ class TicketCategoryController extends Controller
             })
             ->addColumn('actions', function (TicketCategory $category) {
                 return '
-
                            <form class="d-inline" onsubmit="return submitResult();" method="post" action="'.route('moderator.ticket.category.destroy', $category->id).'">
                             '.csrf_field().'
                             '.method_field('DELETE').'

+ 1 - 3
routes/web.php

@@ -221,10 +221,8 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
         Route::get('ticket/blacklist/datatable', [ModTicketsController::class, 'dataTableBlacklist'])->name('ticket.blacklist.datatable');
 
 
-        Route::get('ticket/category', [TicketCategoryController::class, 'index'])->name('ticket.category.index');
         Route::get('ticket/category/datatable', [TicketCategoryController::class, 'datatable'])->name('ticket.category.datatable');
-        Route::post('ticket/category', [TicketCategoryController::class, 'store'])->name('ticket.category.store');
-        Route::delete('ticket/category/destroy/{id}', [TicketCategoryController::class, 'destroy'])->name('ticket.category.destroy');
+        Route::resource("ticket/category", TicketCategoryController::class,['as' => 'ticket']);
 
     });
 

+ 32 - 0
themes/default/views/moderator/ticket/category.blade.php

@@ -68,9 +68,36 @@
                             </form>
                         </div>
                     </div>
+                    <div class="card">
+                        <div class="card-header">
+                            <h5 class="card-title">{{__('Edit Category')}}
+                        </div>
+                        <div class="card-body">
+                            <form action="{{route("moderator.ticket.category.update","1")}}" method="POST" class="ticket-form">
+                                @csrf
+                                @method('PATCH')
+                                <select id="category" style="width:100%" class="custom-select" name="category"
+                                        required autocomplete="off" @error('category') is-invalid @enderror>
+                                    @foreach ($categories as $category)
+                                        <option value="{{ $category->id }}">{{ __($category->name) }}</option>
+                                    @endforeach
+                                </select>
+
+                                <div class="form-group ">
+                                    <label for="name" class="control-label">{{__("New Name")}}</label>
+                                    <input id="name" type="text" class="form-control" name="name" required>
+                                </div>
+                                <button type="submit" class="btn btn-primary">
+                                    {{__('Submit')}}
+                                </button>
+                            </form>
+                        </div>
+                    </div>
                 </div>
             </div>
         </div>
+
+
     </section>
     <!-- END CONTENT -->
     <script>
@@ -95,6 +122,11 @@
                 }
             });
         });
+
+            document.addEventListener('DOMContentLoaded', (event) => {
+            $('.custom-select').select2();
+        })
+
     </script>
 @endsection