Installation
composer require mhshohel/appbajarticket
Note: Verify the package is compatible with Laravel 5.1 (original ticketit was built for this version).
Publish Configuration & Migrations
php artisan vendor:publish --provider="AppBajarTicket\Providers\AppBajarTicketServiceProvider"
php artisan migrate
Add Middleware & Routes
In app/Http/Kernel.php, add:
'ticket' => \AppBajarTicket\Http\Middleware\TicketMiddleware::class,
Include routes in routes/web.php:
Route::group(['middleware' => 'web', 'prefix' => 'ticket'], function () {
require __DIR__ . '/ticket-routes.php';
});
First Use Case
/ticket → Create a ticket./ticket/agent → Accept/respond to tickets./ticket/admin → Manage departments, roles, or stats.Ticket Creation
// User creates a ticket (via form submission)
$ticket = \AppBajarTicket\Models\Ticket::create([
'user_id' => auth()->id(),
'subject' => $request->subject,
'message' => $request->message,
'department_id' => $request->department_id,
]);
config/ticketit.php:
'auto_assign' => true,
'assign_to_least_busy' => true,
Agent Assignment & Notifications
assignToAgent() method:
$ticket->assignToAgent($agentId);
events (extend AppBajarTicket\Events\TicketAssigned).Role-Based Permissions
Gate::define('close-ticket', function ($user, $ticket) {
return $user->isAgent() && $ticket->agent_id === $user->id;
});
Department Integration
Billing, Technical):
$ticket->department()->attach($departmentId);
$tickets = Ticket::whereHas('department', function($q) {
$q->where('name', 'Technical');
})->get();
Localization
// config/app.php
'locale' => 'hu', // Hungarian
resources/lang/vendor/ticketit/.via() channels:
use AppBajarTicket\Notifications\TicketAssignedNotification;
TicketAssignedNotification::create($ticket)
->route('mail', $agent->email)
->send();
Route::apiResource('tickets', 'TicketController')->middleware('auth:api');
Ticket model:
class Ticket extends \AppBajarTicket\Models\Ticket
{
protected $casts = [
'priority' => 'integer',
];
}
Laravel 5.1 Dependency
Route::controller() syntax, Auth::user()).composer.json for laravel/framework version constraints.Migration Conflicts
users table structure (e.g., role column) may clash with migrations.php artisan migrate --pretend
database/migrations/ if needed.Auto-Assignment Logic
assign_to_least_busy may not work as expected with custom agent workloads.Agent model:
public function getQueueLengthAttribute()
{
return $this->tickets()->where('status', 'open')->count();
}
Cache::remember("agent_{$this->id}_queue", 60, function() {
return $this->queue_length;
});
Permission Overrides
AuthServiceProvider:
Gate::before(function ($user) {
if ($user->isAdmin()) {
return true; // Bypass all gates
}
});
Email Configuration
resources/views/vendor/ticketit/emails/.config/ticketit.php for auto_assign and assign_to_least_busy.\Log::debug('Agent queues:', [
'agents' => \AppBajarTicket\Models\Agent::withCount('tickets as open_tickets')
->whereHas('tickets', function($q) {
$q->where('status', 'open');
})
->get()
]);
users table (role column) and middleware:
Route::middleware(['auth', 'role:agent'])->group(function () {
// Agent-only routes
});
Custom Ticket Statuses
status field in migrations and add logic to Ticket model:
const STATUS_PENDING = 'pending';
const STATUS_REVIEW = 'review';
status dropdown in views (resources/views/ticketit/partials/status.blade.php).Webhooks for External Systems
ticket.created events:
Event::listen('ticket.created', function ($ticket) {
// Send webhook to Slack/Teams
Http::post('https://hooks.slack.com/...', [
'text' => "New ticket #{$ticket->id} created"
]);
});
Sentry/Error Tracking
try {
$ticket->assignToAgent($agentId);
} catch (\Exception $e) {
\Sentry\captureException($e, [
'ticket_id' => $ticket->id,
'agent_id' => $agentId,
]);
}
Testing
$this->actingAs($user)
->post('/ticket', [
'subject' => 'Test',
'message' => 'Hello',
])
->assertRedirect('/ticket');
$agent = create('AppBajarTicket\Models\Agent');
\AppBajarTicket\Services\TicketAssigner::shouldReceive('assign')
->once()
->andReturn($agent);
How can I help you explore Laravel packages today?