-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from abdosaeedelhassan/master
New updates
- Loading branch information
Showing
7 changed files
with
397 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@extends(config('laravel-tickets.layouts')) | ||
|
||
@section('content') | ||
<div class="card"> | ||
<div class="card-header"> | ||
@lang('Add new category') | ||
</div> | ||
<div class="card-body"> | ||
@includeWhen(session()->has('message'), 'laravel-tickets::alert', ['type' => 'info', 'message' => | ||
session()->get('message')]) | ||
<form method="post" action="{{ route('laravel-tickets.categories.store') }}" | ||
@if(config('laravel-tickets.files')) enctype="multipart/form-data" @endif> | ||
@csrf | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="form-group"> | ||
<label>@lang('Translation')</label> | ||
<textarea class="form-control @error('translation') is-invalid @enderror" | ||
placeholder="@lang('translation')" name="translation">{{ old('translation') }}</textarea> | ||
@error('translation') | ||
<div class="invalid-feedback">{{ $message }}</div> | ||
@enderror | ||
</div> | ||
</div> | ||
<div class="col-12 mt-2"> | ||
<button class="btn btn-primary">@lang('Create')</button> | ||
<a href="{{ route('laravel-tickets.categories.index') }}" class="btn btn-danger">@lang('Cancel')</a> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@extends(config('laravel-tickets.layouts')) | ||
|
||
@section('content') | ||
<div class="card"> | ||
<div class="card-header"> | ||
<div class="d-flex justify-content-between"> | ||
<div> | ||
{{__('Categories')}} | ||
</div> | ||
<div> | ||
<a href="{{ route('laravel-tickets.categories.create') }}" class="btn btn-primary">{{__('Add new')}}</a> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="card-body"> | ||
@includeWhen(session()->has('message'), 'laravel-tickets::alert', ['message' => session()->get('message'),'type' | ||
=> session()->get('type')]) | ||
<div class="table-responsive"> | ||
<table class="table table-striped"> | ||
<thead class="th"> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">{{__('Translation')}}</th> | ||
<th scope="col">@lang('Last Update')</th> | ||
<th scope="col">@lang('Created at')</th> | ||
<th scope="col">{{__('Action')}}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach ($categories as $category) | ||
<tr> | ||
<th scope="row">{{ $category->id }}</th> | ||
<td>{{ $category->translation }}</td> | ||
<td>{{ $category->updated_at ? $category->updated_at->format(config('laravel-tickets.datetime-format')) : trans('Not updated') }} | ||
</td> | ||
<td>{{ $category->created_at ? $category->created_at->format(config('laravel-tickets.datetime-format')) : trans('Not created') }} | ||
</td> | ||
<td> | ||
<div class="d-flex"> | ||
<a href="{{ route('laravel-tickets.categories.show', compact('category')) }}" | ||
class="btn btn-primary m-1">{{__('Show')}}</a> | ||
<a href="{{ route('laravel-tickets.categories.edit', compact('category')) }}" | ||
class="btn btn-success m-1">{{__('Edit')}}</a> | ||
<form method="post" | ||
action="{{ route('laravel-tickets.categories.destroy', compact('category')) }}"> | ||
@csrf | ||
@method('DELETE') | ||
<button class="btn btn-danger m-1">{{__('Delete')}}</button> | ||
</form> | ||
</div> | ||
</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
<div class="mt-2 d-flex justify-content-center"> | ||
{!! $categories->links('pagination::bootstrap-4') !!} | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@extends(config('laravel-tickets.layouts')) | ||
|
||
@section('content') | ||
<div class="row"> | ||
<div class="col-12 col-sm-12 col-md-12 col-lg-8"> | ||
@includeWhen(session()->has('message'), 'laravel-tickets::alert', ['type' => 'info', 'message' => | ||
session()->get('message')]) | ||
</div> | ||
<div class="col-12 col-sm-12 col-md-12 col-lg-12"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
@lang('Category overview') | ||
</div> | ||
<div class="card-body"> | ||
<form @if ($action=='edit' ) method="post" action="{{ route('laravel-tickets.categories.store') }}" | ||
@endif> | ||
<input type="hidden" name="action" value="{{$action}}"> | ||
@if ($action=='edit') | ||
<input type="hidden" name="category_id" value="{{$category->id}}"> | ||
@csrf | ||
@endif | ||
<div class="form-group"> | ||
<label>@lang('Translation'):</label> | ||
<input class="form-control" name="translation" type="text" value="{{ $category->translation }}" | ||
@if($action!='edit' ) disabled @endif> | ||
</div> | ||
<div class="form-group mt-2 d-flex"> | ||
@if ($action=='edit') | ||
<button class="btn btn-success m-1">{{__('Save')}}</button> | ||
@endif | ||
<a href="{{ route('laravel-tickets.categories.index') }}" | ||
class="btn btn-primary m-1">@lang('Back')</a> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
<?php | ||
|
||
|
||
namespace RexlManu\LaravelTickets\Controllers; | ||
|
||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Validation\Rule; | ||
use Illuminate\View\View; | ||
use RexlManu\LaravelTickets\Models\Ticket; | ||
use RexlManu\LaravelTickets\Models\TicketCategory; | ||
use RexlManu\LaravelTickets\Models\TicketMessage; | ||
use RexlManu\LaravelTickets\Models\TicketReference; | ||
use RexlManu\LaravelTickets\Models\TicketUpload; | ||
use RexlManu\LaravelTickets\Rule\TicketReferenceRule; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
|
||
/** | ||
* Class TicketController | ||
* | ||
* The main logic of the ticket system. All actions are performed here. | ||
* | ||
* If the accept header is json, the response will be a json response | ||
* | ||
* @package RexlManu\LaravelTickets\Controllers | ||
*/ | ||
trait CategoryControllable | ||
{ | ||
|
||
/** | ||
* @link CategoryControllable constructor | ||
*/ | ||
public function __construct() | ||
{ | ||
if (!config('laravel-tickets.permission')) { | ||
return; | ||
} | ||
|
||
$this->middleware(config('laravel-tickets.permissions.list-category'))->only('index'); | ||
$this->middleware(config('laravel-tickets.permissions.create-category'))->only('store', 'create'); | ||
$this->middleware(config('laravel-tickets.permissions.show-category'))->only('show'); | ||
$this->middleware(config('laravel-tickets.permissions.edit-category'))->only('edit'); | ||
} | ||
|
||
/** | ||
* Show every @return View|JsonResponse | ||
* | ||
* @link TicketCategory that the user has created | ||
* | ||
* If the accept header is json, the response will be a json response | ||
* | ||
*/ | ||
public function index() | ||
{ | ||
$categories = TicketCategory::orderBy('id', 'desc')->paginate(10); | ||
|
||
return request()->wantsJson() ? | ||
response()->json(compact('categories')) : | ||
view( | ||
'laravel-tickets::categories.index', | ||
compact('categories') | ||
); | ||
} | ||
|
||
/** | ||
* Show the create form | ||
* | ||
* @return View | ||
*/ | ||
public function create() | ||
{ | ||
return view('laravel-tickets::categories.create'); | ||
} | ||
|
||
/** | ||
* Creates a @param Request $request the request | ||
* | ||
* @return View|JsonResponse|RedirectResponse | ||
* @link TicketCategory | ||
* | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$rules = [ | ||
'translation' => ['required', 'string', 'max:191'], | ||
]; | ||
$data = $request->validate($rules); | ||
|
||
if ($request->has('action') && $request->action == 'edit') { | ||
$category = TicketCategory::where('id', $request->category_id)->update( | ||
$request->only('translation') | ||
); | ||
$message = trans('The category was successfully updated'); | ||
} else { | ||
$category = TicketCategory::create( | ||
$request->only('translation') | ||
); | ||
$message = trans('The category was successfully created'); | ||
} | ||
|
||
return $request->wantsJson() ? | ||
response()->json(compact('category')) : | ||
redirect(route( | ||
'laravel-tickets.categories.index' | ||
))->with([ | ||
'message' => $message, | ||
'type' => 'success' | ||
]); | ||
} | ||
|
||
/** | ||
* Show detailed informations about the @param TicketCategory $category | ||
* | ||
* @return View|JsonResponse|RedirectResponse|void | ||
* @link TicketCategory and the informations | ||
* | ||
*/ | ||
public function show(TicketCategory $category) | ||
{ | ||
if ( | ||
!request()->user()->can(config('laravel-tickets.permissions.all-ticket')) | ||
) { | ||
return abort(403); | ||
} | ||
return \request()->wantsJson() ? | ||
response()->json(compact( | ||
'category', | ||
)) : | ||
view( | ||
'laravel-tickets::categories.show', | ||
compact( | ||
'category', | ||
) | ||
)->with(['action' => 'show']); | ||
} | ||
/** | ||
* edit detailed informations about the @param TicketCategory $category | ||
* | ||
* @return View|JsonResponse|RedirectResponse|void | ||
* @link TicketCategory and the informations | ||
* | ||
*/ | ||
public function edit(TicketCategory $category) | ||
{ | ||
if ( | ||
!request()->user()->can(config('laravel-tickets.permissions.all-ticket')) | ||
) { | ||
return abort(403); | ||
} | ||
return \request()->wantsJson() ? | ||
response()->json(compact( | ||
'category', | ||
)) : | ||
view( | ||
'laravel-tickets::categories.show', | ||
compact( | ||
'category', | ||
) | ||
)->with(['action' => 'edit']); | ||
} | ||
|
||
|
||
public function destroy(TicketCategory $category) | ||
{ | ||
if ( | ||
!request()->user()->can(config('laravel-tickets.permissions.all-ticket')) | ||
) { | ||
return abort(403); | ||
} | ||
|
||
$category->delete(); | ||
|
||
$message = trans('The category was successfully deleted'); | ||
|
||
return \request()->wantsJson() ? | ||
response()->json(compact( | ||
'message', | ||
)) : | ||
redirect()->route('laravel-tickets.categories.index') | ||
->with([ | ||
'message' => $message, | ||
'type' => 'success' | ||
]); | ||
} | ||
} |
Oops, something went wrong.