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')}}
+ + +