new helpdesk module

This commit is contained in:
Mark Gregory
2026-06-12 09:41:57 +01:00
parent 67c9bb22d9
commit da35c7eb95
50 changed files with 1874 additions and 270 deletions
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('users', static function (Blueprint $table): void {
if (! Schema::hasColumn('users', 'helpdesk_agent')) {
$table->boolean('helpdesk_agent')->default(false)->after('password');
}
if (! Schema::hasColumn('users', 'helpdesk_admin')) {
$table->boolean('helpdesk_admin')->default(false)->after('helpdesk_agent');
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('users', static function (Blueprint $table): void {
if (Schema::hasColumn('users', 'helpdesk_admin')) {
$table->dropColumn('helpdesk_admin');
}
if (Schema::hasColumn('users', 'helpdesk_agent')) {
$table->dropColumn('helpdesk_agent');
}
});
}
};
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/** @return void */
public function up(): void
{
Schema::create('helpdesk_statuses', static function (Blueprint $table): void {
$table->id();
$table->string('name', 80);
$table->string('slug', 100)->unique();
$table->string('color', 30)->default('zinc');
$table->unsignedSmallInteger('sort_order')->default(0);
$table->boolean('is_closed')->default(false);
$table->timestamps();
});
Schema::create('helpdesk_priorities', static function (Blueprint $table): void {
$table->id();
$table->string('name', 80);
$table->string('slug', 100)->unique();
$table->string('color', 30)->default('zinc');
$table->unsignedSmallInteger('sort_order')->default(0);
$table->timestamps();
});
Schema::create('helpdesk_categories', static function (Blueprint $table): void {
$table->id();
$table->string('name', 120);
$table->string('slug', 140)->unique();
$table->string('color', 30)->default('blue');
$table->text('description')->nullable();
$table->timestamps();
});
Schema::create('helpdesk_projects', static function (Blueprint $table): void {
$table->id();
$table->string('title', 160);
$table->string('slug', 180)->unique();
$table->string('color', 30)->default('blue');
$table->text('description')->nullable();
$table->timestamp('archived_at')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
/** @return void */
public function down(): void
{
Schema::dropIfExists('helpdesk_projects');
Schema::dropIfExists('helpdesk_categories');
Schema::dropIfExists('helpdesk_priorities');
Schema::dropIfExists('helpdesk_statuses');
}
};
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/** @return void */
public function up(): void
{
Schema::create('helpdesk_tickets', static function (Blueprint $table): void {
$table->id();
$table->string('reference', 32)->unique();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->foreignId('agent_id')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('status_id')->constrained('helpdesk_statuses')->restrictOnDelete();
$table->foreignId('priority_id')->constrained('helpdesk_priorities')->restrictOnDelete();
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
$table->string('subject', 200);
$table->longText('body');
$table->timestamp('due_at')->nullable();
$table->timestamp('completed_at')->nullable();
$table->timestamp('last_activity_at')->nullable();
$table->timestamp('archived_at')->nullable();
$table->softDeletes();
$table->timestamps();
$table->index(['status_id', 'priority_id']);
$table->index(['agent_id', 'completed_at']);
$table->index(['user_id', 'created_at']);
$table->index('last_activity_at');
});
}
/** @return void */
public function down(): void
{
Schema::dropIfExists('helpdesk_tickets');
}
};
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/** @return void */
public function up(): void
{
Schema::create('helpdesk_comments', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->longText('body');
$table->boolean('is_internal')->default(false);
$table->timestamps();
$table->index(['ticket_id', 'created_at']);
});
Schema::create('helpdesk_attachments', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('comment_id')->nullable()->constrained('helpdesk_comments')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->string('disk', 80);
$table->string('path', 500);
$table->string('original_name', 255);
$table->string('mime_type', 160)->nullable();
$table->unsignedBigInteger('size')->default(0);
$table->timestamps();
$table->index(['ticket_id', 'created_at']);
});
}
/** @return void */
public function down(): void
{
Schema::dropIfExists('helpdesk_attachments');
Schema::dropIfExists('helpdesk_comments');
}
};
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/** @return void */
public function up(): void
{
Schema::create('helpdesk_category_user', static function (Blueprint $table): void {
$table->id();
$table->foreignId('category_id')->constrained('helpdesk_categories')->cascadeOnDelete();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->timestamps();
$table->unique(['category_id', 'user_id']);
});
}
/** @return void */
public function down(): void
{
Schema::dropIfExists('helpdesk_category_user');
}
};
@@ -1,21 +1,47 @@
<?php
namespace Modules\Helpdesk\Database\Seeders;
declare(strict_types=1);
namespace Modules\Helpdesk\database\seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Modules\Helpdesk\Models\Category;
use Modules\Helpdesk\Models\Priority;
use Modules\Helpdesk\Models\Project;
use Modules\Helpdesk\Models\Status;
class HelpdeskDatabaseSeeder extends Seeder
final class HelpdeskDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
/** @return void */
public function run(): void
{
Model::unguard();
foreach ([
['name' => 'Open', 'slug' => 'open', 'color' => 'blue', 'sort_order' => 10, 'is_closed' => false],
['name' => 'In Progress', 'slug' => 'in-progress', 'color' => 'amber', 'sort_order' => 20, 'is_closed' => false],
['name' => 'Waiting Customer', 'slug' => 'waiting-customer', 'color' => 'purple', 'sort_order' => 30, 'is_closed' => false],
['name' => 'Closed', 'slug' => 'closed', 'color' => 'green', 'sort_order' => 90, 'is_closed' => true],
] as $row) {
Status::query()->updateOrCreate(['slug' => $row['slug']], $row);
}
// $this->call("OthersTableSeeder");
foreach ([
['name' => 'Low', 'slug' => 'low', 'color' => 'zinc', 'sort_order' => 10],
['name' => 'Normal', 'slug' => 'normal', 'color' => 'blue', 'sort_order' => 20],
['name' => 'High', 'slug' => 'high', 'color' => 'orange', 'sort_order' => 30],
['name' => 'Critical', 'slug' => 'critical', 'color' => 'red', 'sort_order' => 40],
] as $row) {
Priority::query()->updateOrCreate(['slug' => $row['slug']], $row);
}
foreach (['General Support', 'Software', 'Hardware', 'Access Request', 'Incident'] as $name) {
Category::query()->updateOrCreate(['slug' => Str::slug($name)], ['name' => $name, 'color' => 'blue']);
}
Project::query()->updateOrCreate(['slug' => 'internal-helpdesk'], [
'title' => 'Internal Helpdesk',
'color' => 'blue',
'description' => 'Default project for internal helpdesk tickets.',
]);
}
}