Skip to content

Commit 4449933

Browse files
authored
Merge pull request #5 from abdosaeedelhassan/master
New updates
2 parents 8f21238 + b517f57 commit 4449933

File tree

7 files changed

+397
-40
lines changed

7 files changed

+397
-40
lines changed

config/config.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/*
4141
* The default guard for authentication middleware
4242
*/
43-
'guard' => [ 'web', 'auth' ],
43+
'guard' => ['web', 'auth'],
4444

4545
/*
4646
* Database tables name
@@ -90,6 +90,13 @@
9090
'show-ticket' => 'can:tickets.show',
9191
'message-ticket' => 'can:tickets.message',
9292
'download-ticket' => 'can:tickets.download',
93+
/**
94+
* Categories
95+
*/
96+
'create-category' => 'can:categories.create',
97+
'list-category' => 'can:categories.index',
98+
'show-category' => 'can:categories.show',
99+
'edit-category' => 'can:categories.edit',
93100
/*
94101
* For administrate tickets
95102
*/
@@ -99,7 +106,7 @@
99106
/*
100107
* The priorities
101108
*/
102-
'priorities' => [ 'LOW', 'MID', 'HIGH' ],
109+
'priorities' => ['LOW', 'MID', 'HIGH'],
103110
/*
104111
* Layout view
105112
*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@extends(config('laravel-tickets.layouts'))
2+
3+
@section('content')
4+
<div class="card">
5+
<div class="card-header">
6+
@lang('Add new category')
7+
</div>
8+
<div class="card-body">
9+
@includeWhen(session()->has('message'), 'laravel-tickets::alert', ['type' => 'info', 'message' =>
10+
session()->get('message')])
11+
<form method="post" action="{{ route('laravel-tickets.categories.store') }}"
12+
@if(config('laravel-tickets.files')) enctype="multipart/form-data" @endif>
13+
@csrf
14+
<div class="row">
15+
<div class="col-12">
16+
<div class="form-group">
17+
<label>@lang('Translation')</label>
18+
<textarea class="form-control @error('translation') is-invalid @enderror"
19+
placeholder="@lang('translation')" name="translation">{{ old('translation') }}</textarea>
20+
@error('translation')
21+
<div class="invalid-feedback">{{ $message }}</div>
22+
@enderror
23+
</div>
24+
</div>
25+
<div class="col-12 mt-2">
26+
<button class="btn btn-primary">@lang('Create')</button>
27+
<a href="{{ route('laravel-tickets.categories.index') }}" class="btn btn-danger">@lang('Cancel')</a>
28+
</div>
29+
</div>
30+
</form>
31+
</div>
32+
</div>
33+
@endsection
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@extends(config('laravel-tickets.layouts'))
2+
3+
@section('content')
4+
<div class="card">
5+
<div class="card-header">
6+
<div class="d-flex justify-content-between">
7+
<div>
8+
{{__('Categories')}}
9+
</div>
10+
<div>
11+
<a href="{{ route('laravel-tickets.categories.create') }}" class="btn btn-primary">{{__('Add new')}}</a>
12+
</div>
13+
</div>
14+
</div>
15+
16+
<div class="card-body">
17+
@includeWhen(session()->has('message'), 'laravel-tickets::alert', ['message' => session()->get('message'),'type'
18+
=> session()->get('type')])
19+
<div class="table-responsive">
20+
<table class="table table-striped">
21+
<thead class="th">
22+
<tr>
23+
<th scope="col">#</th>
24+
<th scope="col">{{__('Translation')}}</th>
25+
<th scope="col">@lang('Last Update')</th>
26+
<th scope="col">@lang('Created at')</th>
27+
<th scope="col">{{__('Action')}}</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
@foreach ($categories as $category)
32+
<tr>
33+
<th scope="row">{{ $category->id }}</th>
34+
<td>{{ $category->translation }}</td>
35+
<td>{{ $category->updated_at ? $category->updated_at->format(config('laravel-tickets.datetime-format')) : trans('Not updated') }}
36+
</td>
37+
<td>{{ $category->created_at ? $category->created_at->format(config('laravel-tickets.datetime-format')) : trans('Not created') }}
38+
</td>
39+
<td>
40+
<div class="d-flex">
41+
<a href="{{ route('laravel-tickets.categories.show', compact('category')) }}"
42+
class="btn btn-primary m-1">{{__('Show')}}</a>
43+
<a href="{{ route('laravel-tickets.categories.edit', compact('category')) }}"
44+
class="btn btn-success m-1">{{__('Edit')}}</a>
45+
<form method="post"
46+
action="{{ route('laravel-tickets.categories.destroy', compact('category')) }}">
47+
@csrf
48+
@method('DELETE')
49+
<button class="btn btn-danger m-1">{{__('Delete')}}</button>
50+
</form>
51+
</div>
52+
</td>
53+
</tr>
54+
@endforeach
55+
</tbody>
56+
</table>
57+
<div class="mt-2 d-flex justify-content-center">
58+
{!! $categories->links('pagination::bootstrap-4') !!}
59+
</div>
60+
</div>
61+
62+
</div>
63+
</div>
64+
@endsection
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@extends(config('laravel-tickets.layouts'))
2+
3+
@section('content')
4+
<div class="row">
5+
<div class="col-12 col-sm-12 col-md-12 col-lg-8">
6+
@includeWhen(session()->has('message'), 'laravel-tickets::alert', ['type' => 'info', 'message' =>
7+
session()->get('message')])
8+
</div>
9+
<div class="col-12 col-sm-12 col-md-12 col-lg-12">
10+
<div class="card">
11+
<div class="card-header">
12+
@lang('Category overview')
13+
</div>
14+
<div class="card-body">
15+
<form @if ($action=='edit' ) method="post" action="{{ route('laravel-tickets.categories.store') }}"
16+
@endif>
17+
<input type="hidden" name="action" value="{{$action}}">
18+
@if ($action=='edit')
19+
<input type="hidden" name="category_id" value="{{$category->id}}">
20+
@csrf
21+
@endif
22+
<div class="form-group">
23+
<label>@lang('Translation'):</label>
24+
<input class="form-control" name="translation" type="text" value="{{ $category->translation }}"
25+
@if($action!='edit' ) disabled @endif>
26+
</div>
27+
<div class="form-group mt-2 d-flex">
28+
@if ($action=='edit')
29+
<button class="btn btn-success m-1">{{__('Save')}}</button>
30+
@endif
31+
<a href="{{ route('laravel-tickets.categories.index') }}"
32+
class="btn btn-primary m-1">@lang('Back')</a>
33+
</form>
34+
</div>
35+
</div>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
40+
@endsection
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<?php
2+
3+
4+
namespace RexlManu\LaravelTickets\Controllers;
5+
6+
7+
use Illuminate\Http\JsonResponse;
8+
use Illuminate\Http\RedirectResponse;
9+
use Illuminate\Http\Request;
10+
use Illuminate\Validation\Rule;
11+
use Illuminate\View\View;
12+
use RexlManu\LaravelTickets\Models\Ticket;
13+
use RexlManu\LaravelTickets\Models\TicketCategory;
14+
use RexlManu\LaravelTickets\Models\TicketMessage;
15+
use RexlManu\LaravelTickets\Models\TicketReference;
16+
use RexlManu\LaravelTickets\Models\TicketUpload;
17+
use RexlManu\LaravelTickets\Rule\TicketReferenceRule;
18+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
19+
20+
/**
21+
* Class TicketController
22+
*
23+
* The main logic of the ticket system. All actions are performed here.
24+
*
25+
* If the accept header is json, the response will be a json response
26+
*
27+
* @package RexlManu\LaravelTickets\Controllers
28+
*/
29+
trait CategoryControllable
30+
{
31+
32+
/**
33+
* @link CategoryControllable constructor
34+
*/
35+
public function __construct()
36+
{
37+
if (!config('laravel-tickets.permission')) {
38+
return;
39+
}
40+
41+
$this->middleware(config('laravel-tickets.permissions.list-category'))->only('index');
42+
$this->middleware(config('laravel-tickets.permissions.create-category'))->only('store', 'create');
43+
$this->middleware(config('laravel-tickets.permissions.show-category'))->only('show');
44+
$this->middleware(config('laravel-tickets.permissions.edit-category'))->only('edit');
45+
}
46+
47+
/**
48+
* Show every @return View|JsonResponse
49+
*
50+
* @link TicketCategory that the user has created
51+
*
52+
* If the accept header is json, the response will be a json response
53+
*
54+
*/
55+
public function index()
56+
{
57+
$categories = TicketCategory::orderBy('id', 'desc')->paginate(10);
58+
59+
return request()->wantsJson() ?
60+
response()->json(compact('categories')) :
61+
view(
62+
'laravel-tickets::categories.index',
63+
compact('categories')
64+
);
65+
}
66+
67+
/**
68+
* Show the create form
69+
*
70+
* @return View
71+
*/
72+
public function create()
73+
{
74+
return view('laravel-tickets::categories.create');
75+
}
76+
77+
/**
78+
* Creates a @param Request $request the request
79+
*
80+
* @return View|JsonResponse|RedirectResponse
81+
* @link TicketCategory
82+
*
83+
*/
84+
public function store(Request $request)
85+
{
86+
$rules = [
87+
'translation' => ['required', 'string', 'max:191'],
88+
];
89+
$data = $request->validate($rules);
90+
91+
if ($request->has('action') && $request->action == 'edit') {
92+
$category = TicketCategory::where('id', $request->category_id)->update(
93+
$request->only('translation')
94+
);
95+
$message = trans('The category was successfully updated');
96+
} else {
97+
$category = TicketCategory::create(
98+
$request->only('translation')
99+
);
100+
$message = trans('The category was successfully created');
101+
}
102+
103+
return $request->wantsJson() ?
104+
response()->json(compact('category')) :
105+
redirect(route(
106+
'laravel-tickets.categories.index'
107+
))->with([
108+
'message' => $message,
109+
'type' => 'success'
110+
]);
111+
}
112+
113+
/**
114+
* Show detailed informations about the @param TicketCategory $category
115+
*
116+
* @return View|JsonResponse|RedirectResponse|void
117+
* @link TicketCategory and the informations
118+
*
119+
*/
120+
public function show(TicketCategory $category)
121+
{
122+
if (
123+
!request()->user()->can(config('laravel-tickets.permissions.all-ticket'))
124+
) {
125+
return abort(403);
126+
}
127+
return \request()->wantsJson() ?
128+
response()->json(compact(
129+
'category',
130+
)) :
131+
view(
132+
'laravel-tickets::categories.show',
133+
compact(
134+
'category',
135+
)
136+
)->with(['action' => 'show']);
137+
}
138+
/**
139+
* edit detailed informations about the @param TicketCategory $category
140+
*
141+
* @return View|JsonResponse|RedirectResponse|void
142+
* @link TicketCategory and the informations
143+
*
144+
*/
145+
public function edit(TicketCategory $category)
146+
{
147+
if (
148+
!request()->user()->can(config('laravel-tickets.permissions.all-ticket'))
149+
) {
150+
return abort(403);
151+
}
152+
return \request()->wantsJson() ?
153+
response()->json(compact(
154+
'category',
155+
)) :
156+
view(
157+
'laravel-tickets::categories.show',
158+
compact(
159+
'category',
160+
)
161+
)->with(['action' => 'edit']);
162+
}
163+
164+
165+
public function destroy(TicketCategory $category)
166+
{
167+
if (
168+
!request()->user()->can(config('laravel-tickets.permissions.all-ticket'))
169+
) {
170+
return abort(403);
171+
}
172+
173+
$category->delete();
174+
175+
$message = trans('The category was successfully deleted');
176+
177+
return \request()->wantsJson() ?
178+
response()->json(compact(
179+
'message',
180+
)) :
181+
redirect()->route('laravel-tickets.categories.index')
182+
->with([
183+
'message' => $message,
184+
'type' => 'success'
185+
]);
186+
}
187+
}

0 commit comments

Comments
 (0)