PHP code example of ticket / ticketit
1. Go to this page and download the library: Download ticket/ticketit library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ticket / ticketit example snippets
'providers' => [
Ticket\Ticketit\TicketitServiceProvider::class,
],
use Ticket\Ticketit\Traits\HasTickets;
class User extends Authenticatable
{
use HasTickets;
protected $fillable = [
'name', 'email', 'password', 'ticketit_admin', 'ticketit_agent'
];
protected $casts = [
'ticketit_admin' => 'boolean',
'ticketit_agent' => 'boolean'
];
}
use Ticket\Ticketit\Traits\HasTickets;
class Customer extends Authenticatable
{
use HasTickets;
protected $guard = 'customer';
protected $fillable = [
'name', 'email', 'password', 'username'
];
}
// Customer Routes
Route::group([
'middleware' => ['web', 'auth:customer'],
'prefix' => 'customer/tickets',
'as' => 'customer.tickets.',
'namespace' => 'Ticket\Ticketit\Controllers'
], function () {
// Basic Ticket Operations
Route::get('/', 'TicketsController@index')->name('index');
Route::get('/create', 'TicketsController@create')->name('create');
Route::post('/', 'TicketsController@store')->name('store');
Route::get('/{id}', 'TicketsController@customerShow')->name('show')
->middleware('Ticket\Ticketit\Middleware\ResAccessMiddleware');
Route::post('/{ticket}/comments', 'CommentsController@store')->name('comments.store');
Route::post('/{id}/reply', 'TicketsController@customerReply')
->name('reply');
});
// Staff Routes
Route::group([
'middleware' => ['web', 'auth:web'],
'prefix' => 'staff/tickets',
'as' => 'staff.tickets.',
'namespace' => 'Ticket\Ticketit\Controllers'
], function () use ($main_route) {
// Basic Staff Routes
Route::middleware('Ticket\Ticketit\Middleware\StaffAuthMiddleware')->group(function() {
Route::get('/', 'TicketsController@staffIndex')->name('index');
Route::get('/dashboard', 'DashboardController@staffDashboard')->name('dashboard');
Route::get('/{id}', 'TicketsController@staffShow')->name('show');
Route::post('/{ticket}/comments', 'CommentsController@store')->name('comments.store');
} });
// Admin only routes
Route::middleware('Ticket\Ticketit\Middleware\AdminAuthMiddleware')->group(function() {
Route::post('/{id}/assign', 'TicketsController@assignTicket')->name('admin.assign');
});
//Agent routes
Route::middleware([
'Ticket\Ticketit\Middleware\AgentAuthMiddleware',
'Ticket\Ticketit\Middleware\ResAccessMiddleware'
])->group(function() {
// Ticket Management
Route::get('/{id}/view', 'TicketsController@agentShow')->name('agent.show');
Route::post('/{id}/status', 'TicketsController@updateStatus')->name('status.update');
});
$ticket = new Ticket();
$ticket->subject = 'Issue Subject';
$ticket->content = 'Issue Description';
$ticket->category_id = 1;
$ticket->priority_id = 1;
$ticket->customer_id = auth()->guard('customer')->id();
$ticket->save();
// Get tickets assigned to agent
$tickets = Ticket::where('agent_id', auth()->id())->get();
// Update ticket status
$ticket->status_id = $newStatusId;
$ticket->save();
// Add comment
$comment = new Comment();
$comment->content = 'Response content';
$comment->ticket_id = $ticket->id;
$comment->user_id = auth()->id();
$comment->save();