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

Ticket Entity Bundle Laravel Package

dervis/ticket-entity-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dervis/ticket-entity-bundle
    

    Add to config/app.php under providers:

    Dervis\TicketBundle\TicketBundle::class,
    
  2. Publish Config (if needed)

    php artisan vendor:publish --provider="Dervis\TicketBundle\TicketBundle" --tag="config"
    

    Check config/ticket.php for default settings.

  3. First Use Case: Basic Ticket Creation Inject the TicketEntity class and its repository:

    use Dervis\TicketBundle\Entity\TicketEntity;
    use Dervis\TicketBundle\Repository\TicketRepository;
    
    public function createTicket(TicketRepository $ticketRepo) {
        $ticket = new TicketEntity();
        $ticket->setTitle('Bug Fix');
        $ticket->setDescription('Fix login issue');
        $ticketRepo->save($ticket);
    }
    
  4. Key Entry Points

    • Entities: Dervis\TicketBundle\Entity\TicketEntity (core model)
    • Repositories: Dervis\TicketBundle\Repository\TicketRepository (CRUD operations)
    • Services: Check for TicketService (if exists in future updates)

Implementation Patterns

Common Workflows

1. Ticket CRUD Operations

// Create
$ticket = $ticketRepo->create(['title' => 'Feature', 'status' => 'open']);

// Read
$ticket = $ticketRepo->find($id);
$tickets = $ticketRepo->findBy(['status' => 'open']);

// Update
$ticket->setStatus('resolved');
$ticketRepo->save($ticket);

// Delete
$ticketRepo->delete($ticket);

2. Integration with Laravel Eloquent

If the bundle uses Eloquent, extend it for custom logic:

use Illuminate\Database\Eloquent\Model;

class CustomTicket extends TicketEntity {
    protected $table = 'custom_tickets';

    public function customScope() {
        return $this->where('priority', 'high');
    }
}

3. Event Listeners

Listen for ticket status changes (if events are supported):

// config/app.php
'events' => [
    Dervis\TicketBundle\Events\TicketStatusChanged::class,
],

// Event listener
public function handleTicketStatusChanged(TicketStatusChanged $event) {
    // Send notification, log, etc.
}

4. API Resource (if applicable)

Create a TicketResource for API responses:

use Illuminate\Http\Resources\Json\JsonResource;

class TicketResource extends JsonResource {
    public function toArray($request) {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'status' => $this->status,
            'created_at' => $this->created_at->toDateTimeString(),
        ];
    }
}

5. Validation Rules

Use Laravel’s validation with the bundle’s entities:

use Dervis\TicketBundle\Rules\ValidTicketStatus;

$validated = $request->validate([
    'status' => ['required', new ValidTicketStatus],
]);

Integration Tips

  1. Database Migrations Check if the bundle includes migrations. If not, create your own:

    php artisan make:migration create_tickets_table --table=custom_tickets
    
  2. Service Container Binding Override the default repository binding:

    $this->app->bind(
        Dervis\TicketBundle\Repository\TicketRepository::class,
        App\Repositories\CustomTicketRepository::class
    );
    
  3. Testing Use Laravel’s testing helpers with the bundle’s entities:

    public function testTicketCreation() {
        $ticket = factory(TicketEntity::class)->create();
        $this->assertDatabaseHas('tickets', ['id' => $ticket->id]);
    }
    
  4. Localization If the bundle supports localization, publish and translate language files:

    php artisan vendor:publish --tag=laravel-translations
    

Gotchas and Tips

Pitfalls

  1. Namespace Conflicts The bundle may use Ticket as a reserved word. Avoid naming models/tables ticket to prevent SQL errors.

  2. Missing Documentation With no stars or dependents, assume minimal docs. Inspect:

    • src/ for classes/interfaces.
    • tests/ for usage examples.
    • config/ticket.php for default values.
  3. Repository Pattern Assumption The bundle likely uses a repository pattern. If you prefer Eloquent directly, override the repository binding (see Integration Tips).

  4. No Built-in API The bundle may lack API endpoints. Use Laravel’s routing to expose functionality:

    Route::apiResource('tickets', TicketController::class);
    
  5. Event System If events exist (e.g., TicketCreated), ensure they’re properly dispatched in the repository/service layer.


Debugging Tips

  1. Check for Traits The TicketEntity may use traits (e.g., Uuids, SoftDeletes). Ensure your database schema supports them.

  2. Enable Query Logging Debug slow queries with:

    DB::enableQueryLog();
    $ticketRepo->find(1);
    dd(DB::getQueryLog());
    
  3. Validate Entity States If the bundle uses state machines (e.g., for status), log transitions:

    $ticket->setStatus('closed');
    logger()->debug('Ticket status changed to: ' . $ticket->getStatus());
    

Extension Points

  1. Custom Fields Extend TicketEntity to add fields:

    class ExtendedTicket extends TicketEntity {
        protected $fillable = ['custom_field'];
    
        public function getCustomFieldAttribute() {
            return $this->attributes['custom_field'];
        }
    }
    
  2. Policy Integration Use Laravel’s policies for authorization:

    php artisan make:policy TicketPolicy --model=TicketEntity
    
  3. Observers Add model observers for side effects:

    TicketEntity::observe(TicketObserver::class);
    
    class TicketObserver {
        public function saved(TicketEntity $ticket) {
            // Send Slack notification, etc.
        }
    }
    
  4. Testing Doubles Mock the repository in tests:

    $mockRepo = Mockery::mock(TicketRepository::class);
    $mockRepo->shouldReceive('find')->andReturn($ticket);
    $this->app->instance(TicketRepository::class, $mockRepo);
    
  5. Configuration Overrides Override bundle config in config/ticket.php:

    'default_status' => 'backlog',
    'allowed_statuses' => ['open', 'closed', 'backlog'],
    
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime