cassianogf/ticket-system
Laravel package for a ticket system (work in progress). Intended to help manage support tickets and related workflows. Project is under construction and documentation is minimal, so expect incomplete features and APIs.
Installation
composer require cassianogf/ticket-system
php artisan vendor:publish --provider="CassianoGF\TicketSystem\TicketSystemServiceProvider" --tag=config
php artisan migrate
Service Provider & Routes
Ensure the package is registered in config/app.php under providers:
CassianoGF\TicketSystem\TicketSystemServiceProvider::class,
Publish routes (if not auto-loaded):
php artisan vendor:publish --provider="CassianoGF\TicketSystem\TicketSystemServiceProvider" --tag=routes
First Use Case
use CassianoGF\TicketSystem\Models\Ticket;
$ticket = Ticket::create([
'title' => 'Test Ticket',
'description' => 'This is a test ticket.',
'user_id' => auth()->id(), // Assuming Laravel auth is set up
]);
/tickets (if routes are published).Ticket Creation
Ticket model to create, update, or delete tickets.use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'title' => 'required|string|max:255',
'description' => 'required|string',
]);
if ($validator->fails()) return redirect()->back()->withErrors($validator);
Ticket::create($validator->validated() + ['user_id' => auth()->id()]);
Assigning Tickets
$ticket->assignTo(User::find(1)); // Assign to user with ID 1
Status Management
open, pending, closed):
$ticket->update(['status' => 'closed']);
Integration with Auth
// In a controller middleware
public function __construct() {
$this->middleware('auth');
}
$tickets = auth()->user()->tickets()->get();
$tickets = Ticket::where('title', 'like', '%test%')->get();
Ticket model or use accessors/mutators:
public function getShortDescriptionAttribute() {
return Str::limit($this->description, 100);
}
Laravel Version Compatibility
laravel-shift or manual polyfills) if needed.Missing Middleware
Route::middleware(['auth'])->group(function () {
Route::resource('tickets', 'TicketController');
});
Demo Overrides
http://ticketit.kordy.info/tickets may not reflect your local setup. Always test locally first.Database Schema Assumptions
users table. If using a custom auth system, update the user_id foreign key in migrations.config/ticket-system.php for customizations (e.g., allowed statuses, default assignee).Ticket::observe(TicketObserver::class);
php artisan route:list to verify published routes.Custom Ticket Fields
Add columns to the tickets table and extend the model:
// Migration
Schema::table('tickets', function (Blueprint $table) {
$table->string('priority')->nullable();
});
// Model
protected $fillable = ['priority'];
Custom Statuses
Override the statuses config array to add/remove options:
'statuses' => [
'open' => 'Open',
'pending' => 'Pending',
'closed' => 'Closed',
'escalated' => 'Escalated', // Custom status
],
API Integration Use Laravel’s API resources to expose tickets:
php artisan make:resource TicketResource
Then return:
return new TicketResource($ticket);
Notifications Extend the package to send notifications (e.g., via Laravel Notifications) when tickets are created/updated:
Ticket::created(function ($ticket) {
$ticket->user->notify(new TicketCreated($ticket));
});
How can I help you explore Laravel packages today?