added ticket controller

pull/44/head
A1Gard 6 months ago
parent 3bfdd29e17
commit b634056dd1

@ -0,0 +1,142 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\TicketSaveRequest;
use App\Models\Access;
use App\Models\Ticket;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class TicketController extends XController
{
// protected $_MODEL_ = Ticket::class;
// protected $SAVE_REQUEST = TicketSaveRequest::class;
protected $cols = ['title','status','customer_id'];
protected $extra_cols = ['id'];
protected $searchable = [];
protected $listView = 'admin.tickets.ticket-list';
protected $formView = 'admin.tickets.ticket-form';
protected $buttons = [
'edit' =>
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
// 'show' =>
// ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
'destroy' =>
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
];
public function __construct()
{
parent::__construct(Ticket::class, TicketSaveRequest::class);
}
/**
* @param $ticket Ticket
* @param $request TicketSaveRequest
* @return Ticket
*/
public function save($ticket, $request)
{
$ticket->save();
return $ticket;
}
public function index()
{
$query = $this->makeSortAndFilter();
$query = $query->whereNull('parent_id');
return $this->showList($query);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view($this->formView);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Ticket $item)
{
//
return view($this->formView, compact('item'));
}
public function bulk(Request $request)
{
// dd($request->all());
$data = explode('.', $request->input('action'));
$action = $data[0];
$ids = $request->input('id');
switch ($action) {
case 'delete':
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
$this->_MODEL_::destroy($ids);
break;
case 'close':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 'CLOSED']);
$msg = __(':COUNT items closed successfully', ['COUNT' => count($ids)]);
break;
case 'pending':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 'PENDING']);
$msg = __(':COUNT items pending successfully', ['COUNT' => count($ids)]);
break;
case 'answered':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 'ANSWERED']);
$msg = __(':COUNT items answered successfully', ['COUNT' => count($ids)]);
break;
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Ticket $item)
{
return parent::delete($item);
}
public function update(Request $request, Ticket $item)
{
$item->answer = $request->answer;
$item->status = $request->status;
$item->save();
if ($request->has('answers')){
foreach ($request->answers as $id => $answer) {
Ticket::whereId($id)->update(['answer' => $answer]);
}
}
logAdmin(__METHOD__,Ticket::class,$item->id);
if ($request->ajax()) {
return ['OK' => true,
"data" => modelWithCustomAttrs($item) ,
"message" => __('As you wished updated successfully'), "id" => $item->id];
} else {
return redirect(getRoute('edit', $item->{$item->getRouteKeyName()}))
->with(['message' => __('As you wished updated successfully')]);
}
}
}

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TicketSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Ticket extends Model
{
// use HasFactory;
public static $ticket_statuses = [['PENDING','ANSWERED','CLOSED']];
public function customer(){
return $this->belongsTo(Customer::class);
}
public function subTickets(){
return $this->hasMany(Ticket::class,'parent_id','id')->orderBy('id');
}
}

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tickets', function (Blueprint $table) {
$table->id();
$table->string('title',128)->nullable()->default(null);
$table->unsignedBigInteger('customer_id');
$table->text('body');
$table->enum('status',['PENDING','ANSWERED','CLOSED'])->default('PENDING');
$table->text('answer')->nullable()->default(null);
$table->unsignedInteger('parent_id')->nullable()->default(null)->index();
$table->timestamps();
$table->foreign('customer_id')->on('customers')
->references('id')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tickets');
}
};

@ -97,12 +97,16 @@ a.btn,a.action-btn,a.circle-btn{
margin: auto;
border-radius: 3px;
}
.status-0{
.status-0,.status-CLOSED {
background: red;
}
.status-1{
.status-ANSWERED{
background: lime;
}
.status-PENDING{
background: gold;
}
.image-x64{
height: 64px;

@ -185,6 +185,11 @@
{{ $item->user?->name??'-' }}
</a>
@break
@case($col == 'customer_id')
<a href="{{route('admin.customer.edit',$item->customer?->id)}}">
{{ $item->customer?->name??'-' }}
</a>
@break
@case($col == 'category_id')
<a href="{{route('admin.category.edit',$item->category?->slug)}}">
{{ $item->category?->name??'-' }}

@ -0,0 +1,70 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit ticket")}} [{{$item->title}}]
@else
{{__("Add new ticket")}}
@endif -
@endsection
@section('form')
<div class="row">
<div class="col-lg-3">
@include('components.err')
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Tips")}}
</h3>
<ul>
<li>
{{__("Recommends")}}
</li>
</ul>
</div>
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit ticket")}} [{{$item->title}}]
@else
{{__("Add new ticket")}}
@endif
</h1>
<div class="card">
<div class="card-body txt-area">{{$item->body}}</div>
<div class="card-footer">
<textarea name="answer" class="form-control" rows="7" placeholder="{{__("Answer")}}..." minlength="5">{{$item->answer}}</textarea>
</div>
</div>
@foreach($item->subTickets as $t)
<div class="card mt-2">
<div class="card-body txt-area">{{$t->body}}</div>
<div class="card-footer">
<textarea name="answers[{{$t->id}}]" class="form-control" rows="7" placeholder="{{__("Answer")}}..." minlength="5">{{$t->answer}}</textarea>
</div>
</div>
@endforeach
<div class="row mt-3">
<div class="col-md">
<button class="btn btn-primary w-100" name="status" value="ANSWERED">
{{__("Send Answer")}}
</button>
</div>
<div class="col-md">
<button class="btn btn-success w-100 " name="status" value="CLOSED">
{{__("Send Answer and close")}}
</button>
</div>
</div>
</div>
</div>
</div>
@endsection

@ -0,0 +1,17 @@
@extends('admin.templates.panel-list-template')
@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Tickets list")}}
@endsection
@section('title')
{{__("Tickets list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
<option value="close"> {{__("Close")}} </option>
<option value="pending"> {{__("Pending")}} </option>
<option value="answered"> {{__("Answered")}} </option>
@endsection

@ -156,7 +156,7 @@
</li>
<li>
<a href="">
<a href="{{route('admin.ticket.index')}}">
<i class="ri-mail-fill"></i>
{{__('Tickets')}}
</a>

@ -64,6 +64,16 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::post('bulk', [\App\Http\Controllers\Admin\DiscountController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\DiscountController::class, "trashed"])->name('trashed');
});
Route::prefix('tickets')->name('ticket.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\TicketController::class, 'index'])->name('index');
// Route::get('create', [\App\Http\Controllers\Admin\TicketController::class, 'create'])->name('create');
Route::post('store', [\App\Http\Controllers\Admin\TicketController::class, 'store'])->name('store');
Route::get('edit/{item}', [\App\Http\Controllers\Admin\TicketController::class, 'edit'])->name('edit');
Route::post('update/{item}', [\App\Http\Controllers\Admin\TicketController::class, 'update'])->name('update');
Route::get('delete/{item}', [\App\Http\Controllers\Admin\TicketController::class, 'destroy'])->name('destroy');
Route::post('bulk', [\App\Http\Controllers\Admin\TicketController::class, "bulk"])->name('bulk');
});
Route::prefix('transports')->name('transport.')->group(
function () {

Loading…
Cancel
Save