Basic 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...

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.