Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ticketid Laravel Package

mirzarizky/ticketid

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mirzarizky/ticketid
    

    Publish the package assets and migrations:

    php artisan vendor:publish --provider="Mirzarizky\TicketId\TicketIdServiceProvider"
    php artisan migrate
    
  2. Configuration: Review config/ticketid.php for default settings (e.g., ticket_prefix, default_status). No further config is needed for basic usage.

  3. First Use Case: Create a ticket via Tinker or a controller:

    use Mirzarizky\TicketId\Models\Ticket;
    
    $ticket = Ticket::create([
        'title' => 'Test Ticket',
        'description' => 'This is a test ticket.',
        'user_id' => auth()->id(), // Authenticated user
    ]);
    

    Access the ticket ID via $ticket->ticket_id (e.g., TST-0001).


Implementation Patterns

Core Workflows

  1. Ticket Creation:

    • Manual: Use Ticket::create() with user_id, title, and description.
    • Form Handling: Bind a form to Mirzarizky\TicketId\Http\Requests\StoreTicketRequest for validation.
    • API: Extend Mirzarizky\TicketId\Http\Controllers\TicketController for RESTful endpoints.
  2. Ticket Management:

    • Status Updates: Use ticket->update(['status' => 'resolved']).
    • Assignments: Attach users to tickets via ticket->users()->attach($userId).
    • Comments: Leverage the built-in Comment model:
      $ticket->comments()->create(['body' => 'Debugging...', 'user_id' => auth()->id()]);
      
  3. Integration with Auth:

    • Authenticated users auto-populate user_id via middleware (TicketId\Middleware\AuthenticateTicketUser).
    • Guest tickets? Override TicketIdServiceProvider::boot() to customize logic.
  4. Custom Fields:

    • Extend the ticket table via migrations (e.g., priority, department_id).
    • Add fields to StoreTicketRequest and UpdateTicketRequest for form validation.
  5. Searching/Filters:

    • Use Eloquent queries:
      $openTickets = Ticket::where('status', 'open')->with('user', 'comments')->get();
      
    • For advanced search, add scopes to Ticket model or use Laravel Scout.

Advanced Patterns

  1. Event Listeners:

    • Listen for ticket.created or ticket.updated to trigger notifications:
      // app/Providers/EventServiceProvider.php
      protected $listen = [
          'ticket.created' => ['App\Listeners\SendTicketCreatedEmail'],
      ];
      
  2. API Resources:

    • Transform tickets with Mirzarizky\TicketId\Http\Resources\TicketResource or create custom resources:
      php artisan make:resource CustomTicketResource
      
  3. Testing:

    • Use createTicket() helper in tests:
      $ticket = createTicket(['title' => 'Test', 'user_id' => $user->id]);
      
    • Mock the TicketIdServiceProvider for isolated testing.
  4. Localization:

    • Override labels (e.g., "Ticket") in language files (resources/lang/en/ticketid.php).

Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • If you’ve modified the tickets table, reset migrations or use Schema::table() to avoid conflicts.
    • Fix: Backup your database before running php artisan migrate.
  2. Ticket ID Generation:

    • The package uses a sequential ID with prefix (e.g., TST-). Customize ticket_prefix in config if needed.
    • Warning: IDs are not UUIDs—avoid assuming uniqueness in URLs without validation.
  3. Authentication Bypass:

    • The AuthenticateTicketUser middleware assumes Laravel’s default auth. For custom auth, override the middleware or use a trait.
  4. Soft Deletes:

    • The Ticket model uses soft deletes. Use withTrashed() or forceDelete() explicitly if needed.
  5. Performance:

    • Eager-load relationships (with('user', 'comments')) to avoid N+1 queries in loops.

Debugging Tips

  1. Log Ticket Events: Add a listener to debug ticket lifecycle:

    // app/Listeners/LogTicketEvents.php
    public function handle($event) {
        \Log::info('Ticket event', ['event' => $event->getName(), 'ticket' => $event->ticket]);
    }
    
  2. Check Middleware: If tickets lack user_id, verify AuthenticateTicketUser is registered in app/Http/Kernel.php.

  3. Validation Errors: Extend StoreTicketRequest to customize rules:

    public function rules()
    {
        return array_merge(parent::rules(), [
            'priority' => 'required|in:low,medium,high',
        ]);
    }
    

Extension Points

  1. Custom Statuses: Add new statuses via migration and update config/ticketid.php:

    'statuses' => [
        'open', 'pending', 'resolved', 'custom_status',
    ],
    
  2. Attachment Support: Extend the Ticket model to support file uploads:

    public function attachments()
    {
        return $this->morphMany('App\Models\Attachment', 'attachable');
    }
    
  3. API Versioning: Use Laravel’s API resources to version endpoints:

    // routes/api.php
    Route::apiResource('v1/tickets', 'TicketController');
    
  4. Webhooks: Integrate with external systems via ticket.created events:

    // app/Listeners/SendWebhook.php
    public function handle($event) {
        Http::post('https://external-service.com/webhook', [
            'ticket_id' => $event->ticket->ticket_id,
        ]);
    }
    

Pro Tips

  • Bulk Actions: Use Laravel’s update() or chunk() for batch ticket updates.
  • Activity Feed: Combine with laravel-activitylog to track ticket changes.
  • Testing: Use TicketFactory (if available) or create() helpers for consistent test data.
  • Documentation: The package lacks docs—explore vendor/mirzarizky/ticketid/src/ for undocumented features (e.g., TicketId::generateId()).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware