⌘K
Noting Found

View all related articles

The Easiest way to build laravel ticketing system.

Open Source 2 mins read

Table of Content

    Introduction

    Laravel Ticket by @ousid is a Laravel Ticket System, to help you manage your tickets easily.

    Prerequisite

    You need to know the following:

    • Need to know PHP
    • Basics on Laravel & the artisan command Laravel
    • Basics on composer Composer

    Why this package?

    When trying to build a ticket system, it takes time, besides if you want the same functionality in more than project, you'll need to repeat your self each time, So this package, will save you time, and you'll build your ticket system in short time.

    Installation

    You can install the package via composer:

    1composer require coderflex/laravel-ticket

    Configuration

    You can publish the config file with:

    1php artisan vendor:publish --tag="ticket-config"

    You can publish and run the migrations with:

    1php artisan vendor:publish --tag="ticket-migrations"

    Before Running the migration, you may publish the config file, and make sure the current tables does not make a conflict with your existing application, and once you are happy with the migration table, you can run

    1php artisan migrate

    Preparing your model

    Add HasTickets trait into your User model, along with CanUseTickets interface

    1...
    2use Coderflex\LaravelTicket\Concerns\HasTickets;
    3use Coderflex\LaravelTicket\Contracts\CanUseTickets;
    4...
    5class User extends Model implements CanUseTickets
    6{
    7 ...
    8 use HasTickets;
    9 ...
    10}

    Usage

    The Basic Usage of this package, is to create a ticket, then associate the labels and the categories to it.

    You can associate as many as categories/labels into a single ticket.

    Here is an example

    1use Coderflex\LaravelTicket\Models\Ticket;
    2use Coderflex\LaravelTicket\Models\Category;
    3use Coderflex\LaravelTicket\Models\Label;
    4 
    5// ...
    6public function store(Request $request)
    7{
    8 /** @var User */
    9 $user = Auth::user();
    10 
    11 $ticket = $user->tickets()
    12 ->create($request->validated());
    13 
    14 $categories = Category::first();
    15 $labels = Label::first();
    16 
    17 $ticket->attachCategories($categories);
    18 $ticket->attachLabels($labels);
    19 
    20 // or you can create the categories & the tickets directly by:
    21 // $ticket->categories()->create(...);
    22 // $ticket->labels()->create(...);
    23 
    24 return redirect(route('tickets.show', $ticket->uuid))
    25 ->with('success', __('Your Ticket Was created successfully.'));
    26}
    27 
    28public function createLabel()
    29{
    30 // If you create a label seperated from the ticket and wants to
    31 // associate it to a ticket, you may do the following.
    32 $label = Label::create(...);
    33 
    34 $label->tickets()->attach($ticket);
    35 
    36 // or maybe
    37 $label->tickets()->detach($ticket);
    38}
    39 
    40public function createCategory()
    41{
    42 // If you create a category/categories seperated from the ticket and wants to
    43 // associate it to a ticket, you may do the following.
    44 $category = Category::create(...);
    45 
    46 $category->tickets()->attach($ticket);
    47 
    48 // or maybe
    49 $category->tickets()->detach($ticket);
    50}
    51// ...

    Handling File Upload

    This package doesn't come with file upload feature (yet) Instead you can use laravel-medialibrary by Spatie, to handle file functionality.

    The steps are pretty straight forward, all what you need to do is the following.

    Extends the Ticket model, by creating a new model file in your application by

    1php artisan make:model Ticket

    Then extend the base Ticket Model, then use InteractWithMedia trait by Spatie package, and the interface HasMedia:

    1namespace App\Models\Ticket;
    2use Spatie\MediaLibrary\HasMedia;
    3use Spatie\MediaLibrary\InteractsWithMedia;
    4 
    5class Ticket extends \Coderflex\LaravelTicket\Models\Ticket implements HasMedia
    6{
    7 use InteractsWithMedia;
    8}

    The rest of the implementation, head to the docs of Spatie package to know more.


    For full documentation instruction, head to Laravel Ticket Repo

    Changelog

    You can follow the changes on this package by accessing the changelog or the releases

    Contributing

    If you want to contribute, feel free to read the CONTRIBUTING guidelines, and make your PR

    Conclusion

    Today we learned about Laravel Ticket package, and how to use it. To make our development process easier and save us time.

    Related Tags

    About the Author

    Oussama's Profile Picture
    Oussama
    Full Stack Web Developer | Technical Writer

    Oussama is an experienced full-stack web developer with a strong focus on Laravel. He's passionate about crafting web applications with Filament and the TALL Stack. With 8+ years of experience, and he's a dedicated open-source contributor.

    Comments

    Join our newsletter

    Subscribe to Our Newsletter and never miss our offers, latest news, Articles, etc.

    We care about the protection of your data. Read our Privacy Policy.