FIXING TICKET SAVE

This commit is contained in:
Mark Gregory
2026-06-12 11:32:47 +01:00
parent 55428efaef
commit 292cda7ffc
7 changed files with 228 additions and 34 deletions
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
use Modules\Helpdesk\Services\TicketService;
final class TicketStoreController extends Controller
{
/**
* Store a new helpdesk ticket using a normal HTTP form post.
*
* This avoids the Livewire update endpoint for ticket creation, which prevents
* proxy/hash update-route 404s from blocking ticket creation.
*
* @param Request $request
* @param TicketService $tickets
* @return RedirectResponse
*/
public function __invoke(Request $request, TicketService $tickets): RedirectResponse
{
$maxUploadKilobytes = (int) config('helpdesk.max_upload_kb', 10240);
$allowedMimes = (array) config('helpdesk.allowed_mimes', ['jpg', 'jpeg', 'png', 'pdf', 'txt', 'doc', 'docx', 'xls', 'xlsx']);
$validated = $request->validate([
'company_id' => ['nullable', 'integer'],
'subject' => ['required', 'string', 'max:200'],
'body' => ['required', 'string', 'min:10'],
'priority_id' => ['required', 'integer', Rule::exists('helpdesk_priorities', 'id')],
'category_id' => ['nullable', 'integer', Rule::exists('helpdesk_categories', 'id')],
'project_id' => ['nullable', 'integer', Rule::exists('helpdesk_projects', 'id')],
'team_id' => ['nullable', 'integer', Rule::exists('helpdesk_teams', 'id')],
'due_at' => ['nullable', 'date'],
'attachments' => ['nullable', 'array'],
'attachments.*' => ['file', 'max:' . $maxUploadKilobytes, 'mimes:' . implode(',', $allowedMimes)],
]);
$user = Auth::user();
abort_if($user === null, 403);
$uploadedFiles = $request->file('attachments', []);
$uploadedFiles = is_array($uploadedFiles) ? $uploadedFiles : [$uploadedFiles];
$ticket = $tickets->create($user, [
'company_id' => $validated['company_id'] ?? null,
'subject' => $validated['subject'],
'body' => $validated['body'],
'priority_id' => $validated['priority_id'],
'category_id' => $validated['category_id'] ?? null,
'project_id' => $validated['project_id'] ?? null,
'team_id' => $validated['team_id'] ?? null,
'due_at' => $validated['due_at'] ?? null,
], $uploadedFiles);
return redirect()
->route('helpdesk.tickets.index')
->with('success', 'Ticket ' . $ticket->reference . ' has been created.');
}
}
@@ -8,7 +8,6 @@ use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
use Modules\Helpdesk\Livewire\HelpdeskDashboardWidget;
@@ -25,16 +24,22 @@ final class HelpdeskServiceProvider extends ServiceProvider
{
/**
* Module name.
*
* @var string
*/
protected string $moduleName = 'Helpdesk';
/**
* Lowercase module name.
*
* @var string
*/
protected string $moduleNameLower = 'helpdesk';
/**
* Register module services.
*
* @return void
*/
public function register(): void
{
@@ -48,6 +53,8 @@ final class HelpdeskServiceProvider extends ServiceProvider
/**
* Bootstrap module services.
*
* @return void
*/
public function boot(): void
{
@@ -60,17 +67,12 @@ final class HelpdeskServiceProvider extends ServiceProvider
$this->registerPolicies();
$this->loadMigrationsFrom(module_path(ModuleInfo::name(), 'Database/Migrations'));
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/livewire-cfc83872/update', $handle)
->middleware('web');
});
}
/**
* Register Livewire components used by the module.
*
* @return void
*/
protected function registerLivewireComponents(): void
{
@@ -84,6 +86,8 @@ final class HelpdeskServiceProvider extends ServiceProvider
/**
* Register policies and gates.
*
* @return void
*/
protected function registerPolicies(): void
{
@@ -95,6 +99,8 @@ final class HelpdeskServiceProvider extends ServiceProvider
/**
* Register helpers.
*
* @return void
*/
protected function registerHelpers(): void
{
@@ -105,6 +111,8 @@ final class HelpdeskServiceProvider extends ServiceProvider
/**
* Dynamically register console commands.
*
* @return void
*/
protected function registerCommands(): void
{
@@ -119,7 +127,7 @@ final class HelpdeskServiceProvider extends ServiceProvider
}
$commands = collect(File::allFiles($commandPath))
->map(fn ($file): string => 'Modules\\'.$this->moduleName.'\\Console\\'.$file->getFilenameWithoutExtension())
->map(fn ($file): string => 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension())
->filter(fn (string $class): bool => class_exists($class))
->values()
->all();
@@ -129,38 +137,44 @@ final class HelpdeskServiceProvider extends ServiceProvider
/**
* Register config publishing.
*
* @return void
*/
protected function registerConfig(): void
{
$this->publishes([
module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower().'.php'),
module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'),
], 'config');
}
/**
* Register module views.
*
* @return void
*/
protected function registerViews(): void
{
$viewPath = resource_path('views/modules/'.ModuleInfo::nameLower());
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([
$sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower().'-module-views']);
], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
Blade::componentNamespace('Modules\Helpdesk\View\Components', 'helpdesk');
Blade::anonymousComponentPath($sourcePath.'/components', 'helpdesk');
Blade::anonymousComponentPath($sourcePath . '/components', 'helpdesk');
}
/**
* Register translations.
*
* @return void
*/
protected function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.ModuleInfo::nameLower());
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
@@ -181,8 +195,8 @@ final class HelpdeskServiceProvider extends ServiceProvider
$paths = [];
foreach (Config::get('view.paths') as $path) {
if (is_dir($path.'/modules/'.ModuleInfo::nameLower())) {
$paths[] = $path.'/modules/'.ModuleInfo::nameLower();
if (is_dir($path . '/modules/' . ModuleInfo::nameLower())) {
$paths[] = $path . '/modules/' . ModuleInfo::nameLower();
}
}
@@ -5,7 +5,30 @@
'subtitle' => 'Raise a new support request with priority, project, category, team and full details.',
])
<form wire:submit.prevent="save" class="space-y-6">
<form
method="POST"
action="{{ route('helpdesk.tickets.store') }}"
enctype="multipart/form-data"
class="space-y-6"
x-data="{
body: @js(old('body', $body ?? '')),
syncBody() {
this.body = this.$refs.bodyEditor.innerHTML;
this.$refs.bodyInput.value = this.body;
},
command(action, value = null) {
this.$refs.bodyEditor.focus();
document.execCommand(action, false, value);
this.syncBody();
},
init() {
this.$refs.bodyEditor.innerHTML = this.body || '';
this.$refs.bodyInput.value = this.body || '';
}
}"
>
@csrf
<div class="rounded-2xl border border-zinc-200 bg-white shadow-sm dark:border-zinc-700 dark:bg-zinc-900">
<div class="border-b border-zinc-200 px-6 py-4 dark:border-zinc-700">
<h2 class="text-lg font-semibold text-zinc-900 dark:text-zinc-100">Ticket details</h2>
@@ -15,17 +38,30 @@
<div class="grid gap-6 p-6 lg:grid-cols-2">
<div class="lg:col-span-2">
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="subject">Subject</label>
<input id="subject" type="text" wire:model.defer="subject" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100" data-dusk="ticket-subject">
<input
id="subject"
name="subject"
type="text"
value="{{ old('subject', $subject ?? '') }}"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-subject"
>
@error('subject') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
@if($companies->isNotEmpty())
<div>
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="company_id">Company</label>
<select id="company_id" wire:model.defer="company_id" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100">
<select
id="company_id"
name="company_id"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
>
<option value="">Select company</option>
@foreach ($companies as $company)
<option value="{{ $company->id }}">{{ $company->name }}</option>
<option value="{{ $company->id }}" @selected((string) old('company_id', $company_id ?? '') === (string) $company->id)>
{{ $company->name }}
</option>
@endforeach
</select>
@error('company_id') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
@@ -34,10 +70,17 @@
<div>
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="priority_id">Priority</label>
<select id="priority_id" wire:model.defer="priority_id" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100" data-dusk="ticket-priority">
<select
id="priority_id"
name="priority_id"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-priority"
>
<option value="">Select priority</option>
@foreach ($priorities as $priority)
<option value="{{ $priority->id }}">{{ $priority->name }}</option>
<option value="{{ $priority->id }}" @selected((string) old('priority_id', $priority_id ?? '') === (string) $priority->id)>
{{ $priority->name }}
</option>
@endforeach
</select>
@error('priority_id') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
@@ -45,10 +88,16 @@
<div>
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="category_id">Category</label>
<select id="category_id" wire:model.defer="category_id" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100">
<select
id="category_id"
name="category_id"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
>
<option value="">Select category</option>
@foreach ($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
<option value="{{ $category->id }}" @selected((string) old('category_id', $category_id ?? '') === (string) $category->id)>
{{ $category->name }}
</option>
@endforeach
</select>
@error('category_id') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
@@ -56,10 +105,16 @@
<div>
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="project_id">Project</label>
<select id="project_id" wire:model.defer="project_id" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100">
<select
id="project_id"
name="project_id"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
>
<option value="">Select project</option>
@foreach ($projects as $project)
<option value="{{ $project->id }}">{{ $project->title ?? $project->name }}</option>
<option value="{{ $project->id }}" @selected((string) old('project_id', $project_id ?? '') === (string) $project->id)>
{{ $project->title ?? $project->name }}
</option>
@endforeach
</select>
@error('project_id') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
@@ -67,10 +122,16 @@
<div>
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="team_id">Team</label>
<select id="team_id" wire:model.defer="team_id" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100">
<select
id="team_id"
name="team_id"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
>
<option value="">Select team</option>
@foreach ($teams as $team)
<option value="{{ $team->id }}">{{ $team->name }}</option>
<option value="{{ $team->id }}" @selected((string) old('team_id', $team_id ?? '') === (string) $team->id)>
{{ $team->name }}
</option>
@endforeach
</select>
@error('team_id') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
@@ -78,25 +139,63 @@
<div>
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="due_at">Due date</label>
<input id="due_at" type="date" wire:model.defer="due_at" class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100">
<input
id="due_at"
name="due_at"
type="date"
value="{{ old('due_at', $due_at ?? '') }}"
class="mt-2 block w-full rounded-xl border-zinc-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
>
@error('due_at') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div class="lg:col-span-2">
<x-helpdesk::html-editor dusk="ticket-body-editor" wire:model="body" label="Details" rows="10" placeholder="Describe the issue, expected outcome, steps to reproduce and any useful context..." />
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Details</label>
<div class="mt-2 overflow-hidden rounded-xl border border-zinc-300 bg-white shadow-sm dark:border-zinc-700 dark:bg-zinc-950">
<div class="flex flex-wrap gap-1 border-b border-zinc-200 bg-zinc-50 p-2 dark:border-zinc-800 dark:bg-zinc-900">
<button type="button" x-on:click="command('bold')" class="rounded-lg px-2 py-1 text-sm font-bold hover:bg-zinc-200 dark:hover:bg-zinc-800">B</button>
<button type="button" x-on:click="command('italic')" class="rounded-lg px-2 py-1 text-sm italic hover:bg-zinc-200 dark:hover:bg-zinc-800">I</button>
<button type="button" x-on:click="command('underline')" class="rounded-lg px-2 py-1 text-sm underline hover:bg-zinc-200 dark:hover:bg-zinc-800">U</button>
<button type="button" x-on:click="command('insertUnorderedList')" class="rounded-lg px-2 py-1 text-sm hover:bg-zinc-200 dark:hover:bg-zinc-800">• List</button>
<button type="button" x-on:click="command('insertOrderedList')" class="rounded-lg px-2 py-1 text-sm hover:bg-zinc-200 dark:hover:bg-zinc-800">1. List</button>
<button type="button" x-on:click="command('formatBlock', 'blockquote')" class="rounded-lg px-2 py-1 text-sm hover:bg-zinc-200 dark:hover:bg-zinc-800">Quote</button>
<button type="button" x-on:click="const url = prompt('URL'); if (url) command('createLink', url)" class="rounded-lg px-2 py-1 text-sm hover:bg-zinc-200 dark:hover:bg-zinc-800">Link</button>
<button type="button" x-on:click="command('removeFormat')" class="rounded-lg px-2 py-1 text-sm hover:bg-zinc-200 dark:hover:bg-zinc-800">Clear</button>
</div>
<div
x-ref="bodyEditor"
contenteditable="true"
x-on:input.debounce.200ms="syncBody"
x-on:blur="syncBody"
class="prose prose-sm min-h-[280px] max-w-none bg-white p-4 text-sm text-zinc-900 outline-none dark:prose-invert dark:bg-zinc-950 dark:text-zinc-100"
data-dusk="ticket-body-editor"
></div>
</div>
<input x-ref="bodyInput" type="hidden" name="body" value="{{ old('body', $body ?? '') }}">
@error('body') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div class="lg:col-span-2">
<label class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200" for="attachments">Attachments</label>
<input id="attachments" type="file" wire:model="attachments" multiple class="mt-2 block w-full rounded-xl border border-zinc-300 bg-white px-3 py-2 text-sm shadow-sm dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100">
<input
id="attachments"
name="attachments[]"
type="file"
multiple
class="mt-2 block w-full rounded-xl border border-zinc-300 bg-white px-3 py-2 text-sm shadow-sm dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100"
>
@error('attachments') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
@error('attachments.*') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
</div>
<div class="flex items-center justify-end gap-3 border-t border-zinc-200 px-6 py-4 dark:border-zinc-700">
<a href="{{ route('helpdesk.tickets.index') }}" class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800">Cancel</a>
<button type="submit" class="rounded-xl bg-blue-600 px-5 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700" data-dusk="ticket-create-submit">Create Ticket</button>
<a href="{{ route('helpdesk.tickets.index') }}" wire:navigate class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800">Cancel</a>
<button type="submit" x-on:click="syncBody" class="rounded-xl bg-blue-600 px-5 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700" data-dusk="ticket-create-submit">Create Ticket</button>
</div>
</div>
</form>
+2
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Modules\Helpdesk\Http\Controllers\HelpdeskController;
use Modules\Helpdesk\Http\Controllers\TicketStoreController;
use Modules\Helpdesk\Livewire\KanbanBoard;
use Modules\Helpdesk\Livewire\SettingsManager;
use Modules\Helpdesk\Livewire\TicketCreate;
@@ -17,4 +18,5 @@ Route::get('/kanban', KanbanBoard::class)->name('kanban');
Route::get('/tickets', TicketIndex::class)->name('tickets.index');
Route::get('/tickets/create', TicketCreate::class)->name('tickets.create');
Route::post('/tickets', TicketStoreController::class)->name('tickets.store');
Route::get('/tickets/{ticket}', TicketShow::class)->name('tickets.show');
Executable → Regular
+9
View File
@@ -28,3 +28,12 @@ versions:
- Changed ticket create save to validate all fields and return to the tickets index after creation to avoid route-model redirect issues.
- Added a root layout replacement containing the Support sidebar menu and Livewire update endpoint configuration.
- Kept module.json version in sync with changelog.yaml.
"1.0.5":
changed:
- Reworked ticket creation to use a normal HTTP POST route instead of the Livewire update endpoint, preventing proxy or hashed Livewire update-route 404s from blocking ticket creation.
- Added a dedicated TicketStoreController for standard ticket creation validation, attachments and redirects.
- Changed the ticket-create Blade form to use real form field names, CSRF protection and a non-Livewire rich HTML editor payload.
- Removed the module-level Livewire update route override so the Helpdesk module no longer changes the application's global Livewire endpoint.
- Kept module.json version in sync with changelog.yaml.
+1 -1
View File
@@ -13,5 +13,5 @@
"Modules\\Helpdesk\\Providers\\HelpdeskServiceProvider"
],
"files": [],
"version": "1.0.4"
"version": "1.0.5"
}
+4
View File
@@ -103,6 +103,10 @@
"@php artisan optimize:clear",
"@php artisan octane:reload"
],
"restart": [
"@php artisan optimize:clear",
"@php artisan octane:reload"
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve --host=localhost\" \"php artisan queue:listen --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"