From 630ebc6b884c4de97b96c645f2e527607340f8a7 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Wed, 1 Feb 2023 11:07:37 +0100 Subject: [PATCH 1/2] Editable Ticket categories --- .../Moderation/TicketCategoryController.php | 120 ++++++++++++++++++ app/Models/TicketCategory.php | 2 +- routes/web.php | 8 ++ .../views/moderator/ticket/category.blade.php | 100 +++++++++++++++ .../views/moderator/ticket/index.blade.php | 3 + 5 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Moderation/TicketCategoryController.php create mode 100644 themes/default/views/moderator/ticket/category.blade.php diff --git a/app/Http/Controllers/Moderation/TicketCategoryController.php b/app/Http/Controllers/Moderation/TicketCategoryController.php new file mode 100644 index 00000000..9ab0b1d1 --- /dev/null +++ b/app/Http/Controllers/Moderation/TicketCategoryController.php @@ -0,0 +1,120 @@ +validate([ + 'name' => 'required|string|max:191', + ]); + + TicketCategory::create($request->all()); + + + 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) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + $category = TicketCategory::where("id",$id)->firstOrFail(); + + if($category->id == 5 ){ //cannot delete "other" category + return back()->with("error","You cannot delete that category"); + } + + $tickets = Ticket::where("ticketcategory_id",$category->id)->get(); + + foreach($tickets as $ticket){ + $ticket->ticketcategory_id = "5"; + $ticket->save(); + } + + $category->delete(); + + return redirect() + ->route('moderator.ticket.category.index') + ->with('success', __('Category removed')); + } + + public function datatable() + { + $query = TicketCategory::withCount("tickets"); + + return datatables($query) + ->addColumn('name', function ( TicketCategory $category) { + return $category->name; + }) + ->editColumn('tickets', function ( TicketCategory $category) { + return $category->tickets_count; + }) + ->addColumn('actions', function (TicketCategory $category) { + return ' + +
+ '.csrf_field().' + '.method_field('DELETE').' + +
+ '; + }) + ->editColumn('created_at', function (TicketCategory $category) { + return $category->created_at ? $category->created_at->diffForHumans() : ''; + }) + ->rawColumns(['actions']) + ->make(); + } +} diff --git a/app/Models/TicketCategory.php b/app/Models/TicketCategory.php index d261f4c1..6bc30927 100644 --- a/app/Models/TicketCategory.php +++ b/app/Models/TicketCategory.php @@ -10,6 +10,6 @@ class TicketCategory extends Model public function tickets() { - return $this->hasMany(Ticket::class); + return $this->hasMany(Ticket::class,'ticketcategory_id'); } } diff --git a/routes/web.php b/routes/web.php index 8f0cf0e4..818a039b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -21,6 +21,7 @@ use App\Http\Controllers\Admin\UserController; use App\Http\Controllers\Admin\VoucherController; use App\Http\Controllers\Auth\SocialiteController; use App\Http\Controllers\HomeController; +use App\Http\Controllers\Moderation\TicketCategoryController; use App\Http\Controllers\Moderation\TicketsController as ModTicketsController; use App\Http\Controllers\NotificationController; use App\Http\Controllers\ProductController as FrontProductController; @@ -218,6 +219,13 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::post('ticket/blacklist/delete/{id}', [ModTicketsController::class, 'blacklistDelete'])->name('ticket.blacklist.delete'); Route::post('ticket/blacklist/change/{id}', [ModTicketsController::class, 'blacklistChange'])->name('ticket.blacklist.change'); 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::get('/home', [HomeController::class, 'index'])->name('home'); diff --git a/themes/default/views/moderator/ticket/category.blade.php b/themes/default/views/moderator/ticket/category.blade.php new file mode 100644 index 00000000..867990c2 --- /dev/null +++ b/themes/default/views/moderator/ticket/category.blade.php @@ -0,0 +1,100 @@ +@extends('layouts.main') + +@section('content') + +
+
+
+
+

{{ __('Ticket Categories') }}

+
+ +
+
+
+ + + +
+
+
+
+
+
+
+
{{__('Categories')}}
+
+
+
+ + + + + + + + + + + + + +
{{__('ID')}}{{__('Name')}}{{__('Tickets')}}{{__('Created At')}}{{__('Actions')}}
+
+
+
+
+
+
+
{{__('Add Category')}} +
+
+
+ @csrf +
+ + +
+ +
+
+
+
+
+
+
+ + +@endsection + diff --git a/themes/default/views/moderator/ticket/index.blade.php b/themes/default/views/moderator/ticket/index.blade.php index fe908a0f..d71b4a75 100644 --- a/themes/default/views/moderator/ticket/index.blade.php +++ b/themes/default/views/moderator/ticket/index.blade.php @@ -30,8 +30,11 @@
{{__('Ticket List')}}
+ + +
From 9420231b58a7162f89a50d299e7cb4fa9efbf50e Mon Sep 17 00:00:00 2001 From: 1day2die Date: Thu, 2 Feb 2023 13:47:21 +0100 Subject: [PATCH 2/2] Edit category name --- .../Moderation/TicketCategoryController.php | 33 +++++++++---------- routes/web.php | 4 +-- .../views/moderator/ticket/category.blade.php | 32 ++++++++++++++++++ 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Moderation/TicketCategoryController.php b/app/Http/Controllers/Moderation/TicketCategoryController.php index 9ab0b1d1..729e2f3c 100644 --- a/app/Http/Controllers/Moderation/TicketCategoryController.php +++ b/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 ' -
'.csrf_field().' '.method_field('DELETE').' diff --git a/routes/web.php b/routes/web.php index 818a039b..c86a0c66 100644 --- a/routes/web.php +++ b/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']); }); diff --git a/themes/default/views/moderator/ticket/category.blade.php b/themes/default/views/moderator/ticket/category.blade.php index 867990c2..28f72358 100644 --- a/themes/default/views/moderator/ticket/category.blade.php +++ b/themes/default/views/moderator/ticket/category.blade.php @@ -68,9 +68,36 @@ +
+
+
{{__('Edit Category')}} +
+
+
+ @csrf + @method('PATCH') + + +
+ + +
+ + +
+
+ + @endsection