Installation
composer require plaidfoxsg/ticketit7
Add the service provider to config/app.php:
'providers' => [
// ...
Plaidfoxsg\Ticketit7\TicketitServiceProvider::class,
],
Publish Config
php artisan vendor:publish --provider="Plaidfoxsg\Ticketit7\TicketitServiceProvider" --tag="config"
Configure config/ticketit.php with your API credentials and desired settings.
First Use Case: Creating a Ticket
use Plaidfoxsg\Ticketit7\Facades\Ticketit;
$ticket = Ticketit::create([
'title' => 'Bug Fix: Login Redirect',
'description' => 'Users are redirected to homepage instead of dashboard.',
'priority' => 'high',
'project_id' => 123,
]);
config/ticketit.php (API endpoints, default settings)app/Facades/Ticketit.php (if extended)src/TicketitServiceProvider.php (bootstrapping logic)$ticket = Ticketit::update($ticketId, ['status' => 'in_progress']);
$tickets = Ticketit::getTickets(['project_id' => 123, 'limit' => 10]);
$ticket = Ticketit::find($ticketId);
Ticketit::bulkUpdate([1, 2, 3], ['status' => 'resolved']);
$projectTickets = Ticketit::getTickets(['project_id' => $project->id]);
public function show(Project $project) {
$tickets = Ticketit::getTickets(['project_id' => $project->id]);
return view('projects.show', compact('project', 'tickets'));
}
// In EventServiceProvider
protected $listen = [
'Plaidfoxsg\Ticketit7\Events\TicketUpdated' => [
'App\Listeners\NotifyTeamSlack',
],
];
// app/Facades/ExtendedTicketit.php
class ExtendedTicketit extends \Plaidfoxsg\Ticketit7\Facades\Ticketit {
public function createFromForm(Request $request) {
return $this->create($request->validate([
'title' => 'required',
'description' => 'required',
]));
}
}
Eloquent Models: Attach tickets to Eloquent models:
class Project extends Model {
public function tickets() {
return $this->hasMany(Ticket::class)->where('project_id', $this->id);
}
}
Sync with Ticketit API periodically via a job.
Nova/Panel: Display tickets in admin panels:
// Nova Resource
public static $displayInNavigation = false;
public static $title = 'Ticket #';
public function fields(Request $request) {
return [
Text::make('Title')->onlyOnDetail(),
Textarea::make('Description')->onlyOnDetail(),
Select::make('Status')->options(Ticketit::getStatuses()),
];
}
$tickets = Cache::remember("project_{$projectId}_tickets", now()->addHours(1), function() use ($projectId) {
return Ticketit::getTickets(['project_id' => $projectId]);
});
API Rate Limits
429 Too Many Requests and implement retries:
use Plaidfoxsg\Ticketit7\Exceptions\RateLimitExceeded;
try {
$ticket = Ticketit::create([...]);
} catch (RateLimitExceeded $e) {
retry()->times(3)->later(5)->try(fn() => Ticketit::create([...]));
}
Project ID Mismatches
project_id in the API matches your Laravel Project model IDs. Use a mapper if needed:
$apiProjectId = ProjectMapper::toApi($project->id);
Webhook Delays
public function handle(TicketUpdated $event) {
if (!Ticket::where('api_id', $event->ticket->id)->exists()) {
// Process update
}
}
Enable Debug Mode
Set debug to true in config/ticketit.php to log API requests/responses:
'debug' => env('APP_DEBUG', false),
Mock API Calls Use a mock HTTP client for testing:
$this->app->bind(\Plaidfoxsg\Ticketit7\Contracts\HttpClient::class, function() {
return new MockHttpClient();
});
Custom HTTP Client Override the default Guzzle client:
// In ServiceProvider
$this->app->bind(
\Plaidfoxsg\Ticketit7\Contracts\HttpClient::class,
\App\Services\CustomTicketitClient::class
);
Event Customization Publish and extend events:
php artisan vendor:publish --provider="Plaidfoxsg\Ticketit7\TicketitServiceProvider" --tag="events"
Then modify app/Events/TicketitEvents.php.
API Response Transformation Override the response handler:
// In a service provider
$this->app->bind(
\Plaidfoxsg\Ticketit7\Contracts\ResponseTransformer::class,
\App\Services\CustomTransformer::class
);
Base URL Overrides The package assumes a default API URL. Override it in config:
'api' => [
'base_url' => env('TICKETIT_API_URL', 'https://api.ticketit.example.com/v1'),
],
Authentication
Supports multiple auth methods (API key, OAuth). Configure in config/ticketit.php:
'auth' => [
'method' => 'api_key',
'api_key' => env('TICKETIT_API_KEY'),
],
Soft Deletes
If the API supports soft deletes, sync with Laravel’s SoftDeletes:
class Ticket extends Model {
use SoftDeletes;
protected $dates = ['deleted_at'];
}
Search Functionality Leverage the API’s search if available:
$results = Ticketit::search('login redirect', ['project_id' => 123]);
Webhook Verification Validate webhook signatures if security is critical:
public function handleIncomingWebhook(Request $request) {
if (!Ticketit::verifyWebhook($request->header('X-Signature'), $request->getContent())) {
abort(403);
}
// Process webhook
}
How can I help you explore Laravel packages today?