Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Laravel Ticket System, to help you manage your tickets easily.

License

NotificationsYou must be signed in to change notification settings

coderflexx/laravel-ticket

Repository files navigation

Laravisit Logo

Latest Version on PackagistGitHub Tests Action StatusGitHub Code Style Action StatusTotal Downloads

Introduction

Laravel Ticket package, is a Backend API to handle your ticket system, with an easy way.

Installation

You can install the package via composer:

composer require coderflex/laravel-ticket

Configuration

You can publish the config file with:

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

You can publish and run the migrations with:

php 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

php artisan migrate

Preparing your model

AddHasTickets trait into yourUser model, along withCanUseTickets interface

...useCoderflex\LaravelTicket\Concerns\HasTickets;useCoderflex\LaravelTicket\Contracts\CanUseTickets;...class Userextends Modelimplements CanUseTickets{    ...use HasTickets;...}

Usage

The Basic Usage of this package, is to create aticket, then associate thelabels and thecategories to it.

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

Here is an example

useCoderflex\LaravelTicket\Models\Ticket;useCoderflex\LaravelTicket\Models\Category;useCoderflex\LaravelTicket\Models\Label;...publicfunctionstore(Request$request){/** @var User */$user = Auth::user();$ticket =$user->tickets()                    ->create($request->validated());$category = Category::first();$label = Label::first();$ticket->attachCategories($category);$ticket->attachLabels($label);// or you can create the categories & the tickets directly by:// $ticket->categories()->create(...);// $ticket->labels()->create(...);returnredirect(route('tickets.show',$ticket->uuid))            ->with('success',__('Your Ticket Was created successfully.'));}publicfunctioncreateLabel(){// If you create a label seperated from the ticket and wants to// associate it to a ticket, you may do the following.$label = Label::create(...);$label->tickets()->attach($ticket);// or maybe$label->tickets()->detach($ticket);}publicfunctioncreateCategory(){// If you create a category/categories seperated from the ticket and wants to// associate it to a ticket, you may do the following.$category = Category::create(...);$category->tickets()->attach($ticket);// or maybe$category->tickets()->detach($ticket);}...

Ticket Table Structure

Column NameTypeDefault
IDintegerNOT NULL
UUIDstringNULL
user_idintegerNOT NULL
titlestringNOT NULL
messagestringNULL
prioritystringlow
statusstringopen
is_resolvedbooleanfalse
is_lockedbooleanfalse
assigned_tointegerNULL
created_attimestampNULL
updated_attimestampNULL

Message Table Structure

Column NameTypeDefault
IDintegerNOT NULL
user_idintegerNOT NULL
ticket_idintegerNOT NULL
messagestringNULL
created_attimestampNULL
updated_attimestampNULL

Label Table Structure

Column NameTypeDefault
IDintegerNOT NULL
namestringNULL
slugstringNULL
is_visiblebooleanfalse
created_attimestampNULL
updated_attimestampNULL

Category Table Structure

Column NameTypeDefault
IDintegerNOT NULL
namestringNULL
slugstringNULL
is_visiblebooleanfalse
created_attimestampNULL
updated_attimestampNULL

API Methods

Ticket API Methods

Theticket model came with handy methods to use, to make your building process easy and fast, and here is the list of the availableAPI:

MethodArgumentsDescriptionExampleChainable
archivevoidarchive the ticket$ticket->archive()
closevoidclose the ticket$ticket->close()
reopenvoidreopen a closed ticket$ticket->reopen()
markAsResolvedvoidmark the ticket as resolved$ticket->markAsResolved()
markAsLockedvoidmark the ticket as locked$ticket->markAsLocked()
markAsUnlockedvoidmark the ticket as unlocked$ticket->markAsUnlocked()
markAsArchivedvoidmark the ticket as archived$ticket->markAsArchived()
closeAsResolvedvoidclose the ticket and marked it as resolved$ticket->closeAsResolved()
closeAsUnresolvedvoidclose the ticket and marked it as unresolved$ticket->closeAsUnresolved()
reopenAsUnresolvedvoidreopen the ticket and marked it as unresolved$ticket->reopenAsUnresolved()
isArchivedvoidcheck if the ticket archived$ticket->isArchived()
isOpenvoidcheck if the ticket open$ticket->isOpen()
isClosedvoidcheck if the ticket closed$ticket->isClosed()
isResolvedvoidcheck if the ticket has a resolved status$ticket->isResolved()
isUnresolvedvoidcheck if the ticket has an unresolved status$ticket->isUnresolved()
isLockedvoidcheck if the ticket is locked$ticket->isLocked()
isUnlockedvoidcheck if the ticket is unlocked$ticket->isUnlocked()
assignTovoidassign ticket to a user$ticket->assignTo($user) or$ticket->assignTo(2)
makePriorityAsLowvoidmake ticket priority as low$ticket->makePriorityAsLow()
makePriorityAsNormalvoidmake ticket priority as normal$ticket->makePriorityAsNormal()
makePriorityAsHighvoidmake ticket priority as high$ticket->makePriorityAsHigh()

TheChainable column, is showing the state for the method, that if it can be chained or not, something like

$ticket->archive()            ->close()            ->markAsResolved();

Ticket Relationship API Methods

Theticket model has also a list of methods for interacting with another related models

MethodArgumentsDescriptionExample
attachLabelsmixed ID,array attributes,bool touchassociate labels into an existing ticket$ticket->attachLabels([1,2,3,4])
syncLabelsModel/array IDs,bool detouchingassociate labels into an existing ticket$ticket->syncLabels([1,2,3,4])
attachCategoriesmixed ID,array attributes,bool touchassociate categories into an existing ticket$ticket->attachCategories([1,2,3,4])
syncCategoriesModel/array IDs,bool detouchingassociate categories into an existing ticket$ticket->syncCategories([1,2,3,4])
messagestring messageadd new message on an existing ticket$ticket->message('A message in a ticket')
messageAsUserModel/null user,string messageadd new message on an existing ticket as a different user$ticket->messageAsUser($user, 'A message in a ticket')

TheattachCategories andsyncCategories methods, is an alternative forattach andsync laravel methods, and if you want to learn more, please take a look at thislink

ThecommentAsUser accepts a user as a first argument, if it's null, theauthenticated user will be user as default.

Ticket Scopes

Theticket model has also a list of scopes to begin filter with.

MethodArgumentsDescriptionExample
closedvoidget the closed ticketsTicket::closed()->get()
openedvoidget the opened ticketsTicket::opened()->get()
archivedvoidget the archived ticketsTicket::archived()->get()
unArchivedvoidget the unArchived ticketsTicket::unArchived()->get()
resolvedvoidget the resolved ticketsTicket::resolved()->get()
lockedvoidget the locked ticketsTicket::locked()->get()
unlockedvoidget the unlocked ticketsTicket::unlocked()->get()
withLowPriorityvoidget the low priority ticketsTicket::withLowPriority()->get()
withNormalPriorityvoidget the normal priority ticketsTicket::withNormalPriority()->get()
withHighPriorityvoidget the high priority ticketsTicket::withHighPriority()->get()
withPrioritystring $priorityget the withPriority ticketsTicket::withPriority('critical')->get()

Category & Label Scopes

MethodArgumentsDescriptionExample
visiblevoidget the visible model recordsLabel::visible()->get()
hiddenvoidget the hidden model recordsCategory::visible()->get()

Handling File Upload

This package doesn't come with file upload feature (yet) Instead you can uselaravel-medialibrary bySpatie,to handle file functionality.

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

Extends theTicket model, by creating a new model file in your application by

php artisan make:model Ticket

Then extend the baseTicket Model, then useInteractWithMedia trait by spatie package, and the interfaceHasMedia:

namespaceApp\Models\Ticket;useSpatie\MediaLibrary\HasMedia;useSpatie\MediaLibrary\InteractsWithMedia;class Ticketextends \Coderflex\LaravelTicket\Models\Ticketimplements HasMedia{use InteractsWithMedia;}

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

Testing

composertest

Changelog

Please seeCHANGELOG for more information on what has changed recently.

Contributing

Please seeCONTRIBUTING for details.

Security Vulnerabilities

Please reviewour security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please seeLicense File for more information.


[8]ページ先頭

©2009-2025 Movatter.jp