From c623e5ef392ed85362f41a20771410ab9e85f7c1 Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Thu, 19 Nov 2020 10:51:57 +0100 Subject: [PATCH] Fixed some bugs, updated readme, removed controller and use instead TicketControllable as trait --- README.md | 27 +++++++++++++- resources/lang/de.json | 36 +++++++++++++++++++ resources/views/tickets/show.blade.php | 16 ++++----- ...tController.php => TicketControllable.php} | 6 ++-- src/LaravelTicketsServiceProvider.php | 34 +++++++++--------- 5 files changed, 87 insertions(+), 32 deletions(-) create mode 100644 resources/lang/de.json rename src/Controllers/{TicketController.php => TicketControllable.php} (98%) diff --git a/README.md b/README.md index 002683b..cc24f1d 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,33 @@ class User The ticket routes can be implemented via the macro ```php -Route::tickets(); + +class TicketController extends Controller { + + use \RexlManu\LaravelTickets\Controllers\TicketControllable; + +} + +Route::tickets( TicketController::class ); +``` + +For ticket referneces +```php + +class ExampleModel extends Model implements \RexlManu\LaravelTickets\Interfaces\TicketReference { + + use \RexlManu\LaravelTickets\Traits\HasTicketReference; + + // Check if user has access to this model + function hasReferenceAccess() : bool { + return request()->user()->user_id == $this->user_id; + } + +} + ``` +Add this model to the list of reference models now +and Then you should see this model as reference Config: All points of the configuration are documented. diff --git a/resources/lang/de.json b/resources/lang/de.json new file mode 100644 index 0000000..af4b0ab --- /dev/null +++ b/resources/lang/de.json @@ -0,0 +1,36 @@ +{ + "You have reached the limit of open tickets": "Sie haben die Grenze der offenen Tickets erreicht", + "The ticket was successfully created": "Das Ticket wurde erfolgreich erstellt", + "You cannot reply to a closed ticket": "Sie können nicht auf ein geschlossenes Ticket antworten.", + "Your answer was sent successfully": "Ihre Antwort wurde erfolgreich gesendet", + "The ticket is already closed": "Das Ticket ist bereits geschlossen", + "The ticket was successfully closed": "Das Ticket wurde erfolgreich abgeschlossen", + "High": "Hoch", + "Mid": "Mittel", + "Low": "Niedrig", + "Closed": "Geschlossen", + "Open": "Offen", + "Answer": "Beantwortet", + "Reference": "Bezug", + "Subject": "Betreff", + "Priority": "Priorität", + "State": "Status", + "Choose files": "Wähle Dateien aus", + "Ticket answer": "Ticket beantworten", + "Send": "Absenden", + "Ticket overview": "Ticket Übersicht", + "Message": "Nachricht", + "No reference": "Kein Bezug", + "Create": "Erstellen", + "Open ticket": "Ticket eröffnen", + "Last Update": "Letzte Aktualisierung", + "Created at": "Erstellt am", + "Action": "Aktion", + "Show": "Anzeigen", + "Close ticket": "Ticket schließen", + "Not updated": "Nicht aktualisiert", + "Deleted user": "Benutzer gelöscht", + "The reference is not valid": "Der Bezug ist ungültig", + "Category": "Kategorie" +} + diff --git a/resources/views/tickets/show.blade.php b/resources/views/tickets/show.blade.php index 71b5cf4..f75a210 100644 --- a/resources/views/tickets/show.blade.php +++ b/resources/views/tickets/show.blade.php @@ -12,9 +12,7 @@
+ @if (config('laravel-tickets.files')) enctype="multipart/form-data" @endif> @csrf @@ -39,9 +37,7 @@ class="custom-file-input @error('files') is-invalid @enderror" id="files"> @endif @foreach ($messages as $message) -
+
@@ -57,8 +53,8 @@ class="custom-file-input @error('files') is-invalid @enderror" id="files"> {!! nl2br(e($message->message)) !!}
-
- @if ($message->uploads()->count() > 0) + @if ($message->uploads()->count() > 0) +
@foreach ($message->uploads()->get() as $ticketUpload)
@@ -68,8 +64,8 @@ class="custom-file-input @error('files') is-invalid @enderror" id="files">
@endforeach
- @endif -
+
+ @endif
@endforeach diff --git a/src/Controllers/TicketController.php b/src/Controllers/TicketControllable.php similarity index 98% rename from src/Controllers/TicketController.php rename to src/Controllers/TicketControllable.php index 2c945af..59d611c 100644 --- a/src/Controllers/TicketController.php +++ b/src/Controllers/TicketControllable.php @@ -4,11 +4,9 @@ namespace RexlManu\LaravelTickets\Controllers; -use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; use Illuminate\Validation\Rule; use Illuminate\View\View; use RexlManu\LaravelTickets\Events\TicketCloseEvent; @@ -30,11 +28,11 @@ * * @package RexlManu\LaravelTickets\Controllers */ -class TicketController extends Controller +trait TicketControllable { /** - * @link TicketController constructor + * @link TicketControllable constructor */ public function __construct() { diff --git a/src/LaravelTicketsServiceProvider.php b/src/LaravelTicketsServiceProvider.php index d13e421..3161a8b 100644 --- a/src/LaravelTicketsServiceProvider.php +++ b/src/LaravelTicketsServiceProvider.php @@ -4,7 +4,7 @@ use Illuminate\Support\ServiceProvider; use RexlManu\LaravelTickets\Commands\AutoCloseCommand; -use RexlManu\LaravelTickets\Controllers\TicketController; +use RexlManu\LaravelTickets\Controllers\TicketControllable; use Illuminate\Routing\Router; use Illuminate\Support\Facades\Route; use RexlManu\LaravelTickets\Models\Ticket; @@ -24,7 +24,7 @@ public function boot() /* * Optional methods to load your package assets */ -// $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'laravel-tickets'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'laravel-tickets'); $this->loadViewsFrom(__DIR__ . '/../resources/views', 'laravel-tickets'); $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); $this->routes(); @@ -50,9 +50,9 @@ public function boot() ], 'assets');*/ // Publishing the translation files. -// $this->publishes([ -// __DIR__ . '/../resources/lang' => resource_path('lang/vendor/laravel-tickets'), -// ], 'lang'); + $this->publishes([ + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/laravel-tickets'), + ], 'lang'); // Registering package commands. $this->commands([ AutoCloseCommand::class ]); @@ -77,18 +77,18 @@ public function routes() { // Macro routing foreach ([ 'ticketSystem', 'tickets' ] as $routeMacroName) { - Router::macro($routeMacroName, function () { - Route::middleware(config('laravel-tickets.guard'))->name('laravel-tickets.')->group(function () { - Route::prefix('/tickets')->group(function () { - Route::get('/', [ TicketController::class, 'index' ])->name('tickets.index'); - Route::post('/', [ TicketController::class, 'store' ])->name('tickets.store'); - Route::get('/create', [ TicketController::class, 'create' ])->name('tickets.create'); - Route::prefix('{ticket}')->group(function () { - Route::get('/', [ TicketController::class, 'show' ])->name('tickets.show'); - Route::post('/', [ TicketController::class, 'close' ])->name('tickets.close'); - Route::post('/message', [ TicketController::class, 'message' ])->name('tickets.message'); - Route::prefix('{ticketUpload}')->group(function () { - Route::get('/download', [ TicketController::class, 'download' ])->name('tickets.download'); + Router::macro($routeMacroName, function ($controller) { + Route::middleware(config('laravel-tickets.guard'))->name('laravel-tickets.')->group(function () use ($controller) { + Route::prefix('/tickets')->group(function () use ($controller) { + Route::get('/', [ $controller, 'index' ])->name('tickets.index'); + Route::post('/', [ $controller, 'store' ])->name('tickets.store'); + Route::get('/create', [ $controller, 'create' ])->name('tickets.create'); + Route::prefix('{ticket}')->group(function () use ($controller) { + Route::get('/', [ $controller, 'show' ])->name('tickets.show'); + Route::post('/', [ $controller, 'close' ])->name('tickets.close'); + Route::post('/message', [ $controller, 'message' ])->name('tickets.message'); + Route::prefix('{ticketUpload}')->group(function () use ($controller) { + Route::get('/download', [ $controller, 'download' ])->name('tickets.download'); }); }); });