diff --git a/composer.json b/composer.json index 0f1f70f..26454d5 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ ], "require": { "php": "^7.4|^8.0", - "illuminate/support": "^8.0|^9.0" + "illuminate/support": "^8.0|^9.0", + "livewire/livewire": "^2.10" }, "require-dev": { "orchestra/testbench": "^6.4", @@ -50,4 +51,4 @@ } } } -} \ No newline at end of file +} diff --git a/config/config.php b/config/config.php index bf2b61e..56324d4 100644 --- a/config/config.php +++ b/config/config.php @@ -97,6 +97,7 @@ 'list-category' => 'can:categories.index', 'show-category' => 'can:categories.show', 'edit-category' => 'can:categories.edit', + 'delete-category' => 'can:categories.delete', /* * For administrate tickets */ diff --git a/resources/views/alert.blade.php b/resources/views/alert.blade.php index b893a0a..9c60648 100644 --- a/resources/views/alert.blade.php +++ b/resources/views/alert.blade.php @@ -1 +1,12 @@ - +
+ @if (session()->has('success')) +
+ {{ session('success') }} +
+ @endif + @if (session()->has('error')) +
+ {{ session('error') }} +
+ @endif +
\ No newline at end of file diff --git a/resources/views/categories/create.blade.php b/resources/views/categories/create.blade.php deleted file mode 100644 index 10b2c53..0000000 --- a/resources/views/categories/create.blade.php +++ /dev/null @@ -1,33 +0,0 @@ -@extends(config('laravel-tickets.layouts')) - -@section('content') -
-
- @lang('Add new category') -
-
- @includeWhen(session()->has('message'), 'laravel-tickets::alert', ['type' => 'info', 'message' => - session()->get('message')]) -
- @csrf -
-
-
- - - @error('translation') -
{{ $message }}
- @enderror -
-
-
- - @lang('Cancel') -
-
-
-
-
-@endsection \ No newline at end of file diff --git a/resources/views/categories/data.blade.php b/resources/views/categories/data.blade.php new file mode 100644 index 0000000..a11433d --- /dev/null +++ b/resources/views/categories/data.blade.php @@ -0,0 +1,12 @@ +@extends(config('laravel-tickets.layouts')) + +@section('content') +
+
+ @lang(Str::ucfirst($action.' category')) +
+
+ +
+
+@endsection \ No newline at end of file diff --git a/resources/views/categories/form.blade.php b/resources/views/categories/form.blade.php new file mode 100644 index 0000000..477c7cb --- /dev/null +++ b/resources/views/categories/form.blade.php @@ -0,0 +1,31 @@ +
+
+
+
+
+ + + @error('translation') +
{{ $message }}
+ @enderror +
+
+
+ @if ($action!='show') + + @lang('Cancel') + @else + @lang('Back') + @endif +
+
+
+
\ No newline at end of file diff --git a/resources/views/categories/index.blade.php b/resources/views/categories/index.blade.php index 5727e75..53e82c3 100644 --- a/resources/views/categories/index.blade.php +++ b/resources/views/categories/index.blade.php @@ -14,8 +14,9 @@
- @includeWhen(session()->has('message'), 'laravel-tickets::alert', ['message' => session()->get('message'),'type' - => session()->get('type')]) + + +
diff --git a/resources/views/categories/show.blade.php b/resources/views/categories/show.blade.php deleted file mode 100644 index 5eb7bce..0000000 --- a/resources/views/categories/show.blade.php +++ /dev/null @@ -1,40 +0,0 @@ -@extends(config('laravel-tickets.layouts')) - -@section('content') -
-
- @includeWhen(session()->has('message'), 'laravel-tickets::alert', ['type' => 'info', 'message' => - session()->get('message')]) -
-
-
-
- @lang('Category overview') -
-
-
- - @if ($action=='edit') - - @csrf - @endif -
- - -
-
- @if ($action=='edit') - - @endif - @lang('Back') - -
-
-
-
-
- -@endsection \ No newline at end of file diff --git a/resources/views/tickets/form.blade.php b/resources/views/tickets/form.blade.php new file mode 100644 index 0000000..caec35e --- /dev/null +++ b/resources/views/tickets/form.blade.php @@ -0,0 +1,3 @@ +
+ let do it +
\ No newline at end of file diff --git a/src/Components/Alerts.php b/src/Components/Alerts.php new file mode 100644 index 0000000..777dbf3 --- /dev/null +++ b/src/Components/Alerts.php @@ -0,0 +1,13 @@ +action = $action; + $this->category = $category; + + if ($category) { + $this->translation = $category->translation; + } + } + + public function render() + { + return view('laravel-tickets::categories.form'); + } + + public function store() + { + $this->validate([ + 'translation' => ['required', 'string', 'max:191'], + ], [], [ + 'translation' => __('Translation') + ]); + + if ($this->action == 'edit') { + $this->category->translation = $this->translation; + $this->category->save(); + session()->flash('success', __('The category was successfully updated')); + } else if ($this->action == 'add') { + TicketCategory::create( + [ + 'translation' => $this->translation + ] + ); + session()->flash('success', __('The category was successfully created')); + } + + return redirect()->to(route('laravel-tickets.categories.index')); + } +} diff --git a/src/Components/Tickets/TicketForm.php b/src/Components/Tickets/TicketForm.php new file mode 100644 index 0000000..c8fbe66 --- /dev/null +++ b/src/Components/Tickets/TicketForm.php @@ -0,0 +1,13 @@ +with([ + 'action' => 'add', + 'category' => new TicketCategory + ]); } - - /** - * 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 * @@ -129,7 +87,7 @@ public function show(TicketCategory $category) 'category', )) : view( - 'laravel-tickets::categories.show', + 'laravel-tickets::categories.data', compact( 'category', ) @@ -154,7 +112,7 @@ public function edit(TicketCategory $category) 'category', )) : view( - 'laravel-tickets::categories.show', + 'laravel-tickets::categories.data', compact( 'category', ) @@ -172,7 +130,9 @@ public function destroy(TicketCategory $category) $category->delete(); - $message = trans('The category was successfully deleted'); + $message = __('The category was successfully deleted'); + + session()->flash('success', $message); return \request()->wantsJson() ? response()->json(compact( diff --git a/src/LaravelTicketsServiceProvider.php b/src/LaravelTicketsServiceProvider.php index 4ec0948..f336ab8 100644 --- a/src/LaravelTicketsServiceProvider.php +++ b/src/LaravelTicketsServiceProvider.php @@ -5,7 +5,10 @@ use Illuminate\Routing\Router; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; +use Livewire\Livewire; use RexlManu\LaravelTickets\Commands\AutoCloseCommand; +use RexlManu\LaravelTickets\Components\Alerts; +use RexlManu\LaravelTickets\Components\Categories\CategoryForm; use RexlManu\LaravelTickets\Models\Ticket; use RexlManu\LaravelTickets\Models\TicketMessage; use RexlManu\LaravelTickets\Models\TicketUpload; @@ -58,6 +61,12 @@ public function boot() $this->commands([AutoCloseCommand::class]); } } + + /** + * Register components + */ + Livewire::component('laravel-tickets::alerts', Alerts::class); + Livewire::component('laravel-tickets::category-form', CategoryForm::class); } /**