fereydooni / laravel-ticketable
A robust ticketing system for Laravel applications using PHP attributes
dev-main
2025-04-24 13:18 UTC
Requires
- php: ^8.1
- laravel/framework: ^10.0
Requires (Dev)
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/phpstan: ^1.10
This package is auto-updated.
Last update: 2025-04-24 13:31:57 UTC
README
A feature-rich ticketing system for Laravel applications using PHP attributes.
Features
- Create and manage tickets with customizable categories, priorities, and statuses
- Assign tickets to users
- Add comments with Markdown support
- Attach files to tickets and comments
- Track ticket status changes
- Send notifications for ticket events
- Filter and search tickets
Requirements
- PHP 8.1+
- Laravel 10.x
Installation
1. Install the package via Composer
composer require fereydooni/laravel-ticketable
2. Publish the configuration file
php artisan vendor:publish --provider="Fereydooni\LaravelTicketable\TicketingServiceProvider" --tag="config"
3. Run the migrations
php artisan migrate
Configuration
After publishing the configuration file, you can modify the settings in config/ticketing.php
:
return [ 'features' => [ 'attachments' => true, 'notifications' => true, 'markdown_support' => true, 'soft_deletes' => true, ], 'defaults' => [ 'status' => 'open', 'priority' => 'medium', 'category' => 'general', ], // ... more configuration options ];
Usage
Using PHP Attributes
The package provides two main attributes:
1. Ticketable
Attribute (for classes)
use Fereydooni\LaravelTicketable\Attributes\Ticketable; #[Ticketable(category: 'bug', priority: 'high', assignable: true)] class YourModel extends Model { // Your model implementation }
2. TicketAction
Attribute (for methods)
use Fereydooni\LaravelTicketable\Attributes\TicketAction; class YourClass { #[TicketAction(action: 'comment', notify: true)] public function addComment($user, $content) { // Method implementation } }
Using the TicketManager
The package provides a TicketManager
class to handle ticket operations:
use Fereydooni\LaravelTicketable\Services\TicketManager; // Inject via dependency injection public function __construct(TicketManager $ticketManager) { $this->ticketManager = $ticketManager; } // Or resolve from the container $ticketManager = app(TicketManager::class); // Create a ticket $ticket = $ticketManager->create([ 'title' => 'App Crash', 'description' => 'App crashes on login.', 'category' => 'bug', 'priority' => 'high', 'creator_id' => auth()->id(), ]); // Assign a ticket $ticketManager->assign($ticket, User::find(2)); // Add a comment $ticketManager->addComment($ticket, auth()->user(), 'Please provide logs.'); // Attach a file $ticketManager->attachFile($ticket, $request->file('log'), auth()->user()); // Update status $ticketManager->updateStatus($ticket, 'in_progress'); // Find tickets with filters $tickets = $ticketManager->findTickets([ 'category' => 'bug', 'priority' => 'high', 'status' => 'open', 'assigned_to' => 2, 'search' => 'crash', ]);
Using the Facade
The package also provides a Ticket
facade for easier access:
use Fereydooni\LaravelTicketable\Facades\Ticket; // Create a ticket $ticket = Ticket::create([ 'title' => 'App Crash', 'description' => 'App crashes on login.', 'category' => 'bug', 'priority' => 'high', ]); // Assign a ticket Ticket::assign($ticket, User::find(2)); // Add a comment Ticket::addComment($ticket, auth()->user(), 'Please provide logs.'); // Attach a file Ticket::attachFile($ticket, $request->file('log'), auth()->user());
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.