Skip to content

Commit b53d2e0

Browse files
committed
update README.md
1 parent 923eddd commit b53d2e0

File tree

3 files changed

+80
-16
lines changed

3 files changed

+80
-16
lines changed

README.md

+79-15
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,27 @@
88
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/coderflexx/laravel-ticket/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/coderflexx/laravel-ticket/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
99
[![Total Downloads](https://img.shields.io/packagist/dt/coderflexx/laravel-ticket.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravel-ticket)
1010

11+
- [Introduction](#introduction)
12+
- [Installation](#installation)
13+
- [Configuration](#configuration)
14+
- [Usage](#usage)
15+
- [Ticket Table Structure](#ticket-table-structure)
16+
- [Message Table Structure](#message-table-structure)
17+
- [Label Table Structure](#label-table-structure)
18+
- [Category Table Structure](#category-table-structure)
19+
- [API Methods](#api-methods)
20+
- [Ticket API Methods](#ticket-api-methods)
21+
- [Ticket Relationship API Methods](#ticket-relationship-api-methods)
22+
- [Category & Label Scopes](#category--label-scopes)
23+
- [Testing](#testing)
24+
- [Changelog](#changelog)
25+
- [Contributing](#contributing)
26+
- [Security Vulnerabilities](#security-vulnerabilities)
27+
- [Credits](#credits)
28+
- [License](#license)
1129

1230
## Introduction
13-
__Laravel Ticket__ package, is a an Backend API to handle your ticket system, with an easy way.
31+
__Laravel Ticket__ package, is a Backend API to handle your ticket system, with an easy way.
1432

1533
## Installation
1634

@@ -33,12 +51,27 @@ You can publish and run the migrations with:
3351
```bash
3452
php artisan vendor:publish --tag="ticket-migrations"
3553
```
36-
Before Running the migration, you may publish the config file, and make sure the current tables does not make a confilict with your existing application, and once you are happy with the migration table, you can run
54+
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
3755

3856
```bash
3957
php artisan migrate
4058
```
4159

60+
Add `HasTickets` trait into your `User` model, along with `CanUseTickets` interface
61+
62+
```php
63+
...
64+
use Coderflex\LaravelTicket\Concerns\HasTickets;
65+
use Coderflex\LaravelTicket\Contracts\CanUseTickets;
66+
...
67+
class User extends Model implements CanUseTickets
68+
{
69+
...
70+
use HasTickets;
71+
...
72+
}
73+
```
74+
4275
## Usage
4376

4477
The Basic Usage of this package, is to create a `ticket`, then associate the `labels` and the `categories` to it.
@@ -74,14 +107,39 @@ public function store(Request $request)
74107
return redirect(route('tickets.show', $ticket->uuid))
75108
->with('success', __('Your Ticket Was created successfully.'));
76109
}
110+
111+
public function createLabel()
112+
{
113+
// If you create a label seperated from the ticket and wants to
114+
// associate it to a ticket, you may do the following.
115+
$label = Label::create(...);
116+
117+
$label->tickets()->attach($ticket);
118+
119+
// or maybe
120+
$label->tickets()->detach($ticket);
121+
}
122+
123+
public function createCategory()
124+
{
125+
// If you create a category/categories seperated from the ticket and wants to
126+
// associate it to a ticket, you may do the following.
127+
$category = Category::create(...);
128+
129+
$category->tickets()->attach($ticket);
130+
131+
// or maybe
132+
$category->tickets()->detach($ticket);
133+
}
77134
...
78135
```
136+
79137
### Ticket Table Structure
80138

81139
| Column Name | Type | Default |
82140
|---|---|---|
83-
| id |`integer` | `NOT NULL` |
84-
| uuid |`string` | `NULL` |
141+
| ID |`integer` | `NOT NULL` |
142+
| UUID |`string` | `NULL` |
85143
| user_id |`integer` | `NOT NULL` |
86144
| title |`string` | `NOT NULL` |
87145
| message |`string` | `NULL` |
@@ -96,7 +154,7 @@ public function store(Request $request)
96154

97155
| Column Name | Type | Default |
98156
|---|---|---|
99-
| id |`integer` | `NOT NULL` |
157+
| ID |`integer` | `NOT NULL` |
100158
| user_id |`integer` | `NOT NULL` |
101159
| ticket_id |`integer` | `NOT NULL` |
102160
| message |`string` | `NULL` |
@@ -107,7 +165,7 @@ public function store(Request $request)
107165

108166
| Column Name | Type | Default |
109167
|---|---|---|
110-
| id |`integer` | `NOT NULL` |
168+
| ID |`integer` | `NOT NULL` |
111169
| name |`string` | `NULL` |
112170
| slug |`string` | `NULL` |
113171
| is_visible |`boolean` | `false` |
@@ -118,7 +176,7 @@ public function store(Request $request)
118176

119177
| Column Name | Type | Default |
120178
|---|---|---|
121-
| id |`integer` | `NOT NULL` |
179+
| ID |`integer` | `NOT NULL` |
122180
| name |`string` | `NULL` |
123181
| slug |`string` | `NULL` |
124182
| is_visible |`boolean` | `false` |
@@ -128,7 +186,7 @@ public function store(Request $request)
128186
## API Methods
129187

130188
### Ticket API Methods
131-
The `ticket` model came with a handy methods to use, to make your building process easy and fast, and here is the list of the availabel __API__:
189+
The `ticket` model came with handy methods to use, to make your building process easy and fast, and here is the list of the available __API__:
132190

133191
| Method | Arguments | Description | Example | Chainable |
134192
|---|---|---|---|---|
@@ -146,7 +204,7 @@ The `ticket` model came with a handy methods to use, to make your building proce
146204
| `isOpen` |`void` | check if the ticket open | `$ticket->isOpen()` | ✗
147205
| `isClosed` |`void` | check if the ticket closed | `$ticket->isClosed()` | ✗
148206
| `isResolved` |`void` | check if the ticket has a resolved status | `$ticket->isResolved()` | ✗
149-
| `isUnresolved` |`void` | check if the ticket has a unresolved status | `$ticket->isUnresolved()` | ✗
207+
| `isUnresolved` |`void` | check if the ticket has an unresolved status | `$ticket->isUnresolved()` | ✗
150208
| `isLocked` |`void` | check if the ticket is locked | `$ticket->isLocked()` | ✗
151209
| `isUnlocked` |`void` | check if the ticket is unlocked | `$ticket->isUnlocked()` | ✗
152210

@@ -156,22 +214,28 @@ The __Chainable__ column, is showing the state for the method, that if it can be
156214
->close()
157215
->markAsResolved();
158216
```
159-
## Ticket Relashionship API Methods
217+
### Ticket Relationship API Methods
160218
The `ticket` model has also a list of methods for interacting with another related models
161219

162220
| Method | Arguments | Description | Example |
163221
|---|---|---|---|
164-
| `attachLabels` |`mixed` id, `array` attributes, `bool` touch | associate labels into an existing ticket | `$ticket->attachLabels([1,2,3,4])` |
165-
| `syncLabels` |`Model/array` ids, `bool` detouching | associate labels into an existing ticket | `$ticket->syncLabels([1,2,3,4])` |
166-
| `attachCategories` |`mixed` id, `array` attributes, `bool` touch | associate categories into an existing ticket | `$ticket->attachCategories([1,2,3,4])` |
167-
| `syncCategories` |`Model/array` ids, `bool` detouching | associate categories into an existing ticket | `$ticket->syncCategories([1,2,3,4])` |
222+
| `attachLabels` |`mixed` ID, `array` attributes, `bool` touch | associate labels into an existing ticket | `$ticket->attachLabels([1,2,3,4])` |
223+
| `syncLabels` |`Model/array` IDs, `bool` detouching | associate labels into an existing ticket | `$ticket->syncLabels([1,2,3,4])` |
224+
| `attachCategories` |`mixed` ID, `array` attributes, `bool` touch | associate categories into an existing ticket | `$ticket->attachCategories([1,2,3,4])` |
225+
| `syncCategories` |`Model/array` IDs, `bool` detouching | associate categories into an existing ticket | `$ticket->syncCategories([1,2,3,4])` |
168226
| `message` |`string` message | add new message on an existing ticket | `$ticket->message('A message in a ticket')` |
169-
| `messageAsUser` |`Model/null` user, `string` message | add new message on an existing ticket as a deffrent user | `$ticket->messageAsUser($user, 'A message in a ticket')` |
227+
| `messageAsUser` |`Model/null` user, `string` message | add new message on an existing ticket as a different user | `$ticket->messageAsUser($user, 'A message in a ticket')` |
170228

171229
> The `attachCategories` and `syncCategories` methods, is an alternative for `attach` and `sync` laravel methods, and if you want to learn more, please take a look at this [link](https://laravel.com/docs/9.x/eloquent-relationships#attaching-detaching)
172230
173231
The `commentAsUser` accepts a user as a first argument, if it's null, the __authenticated__ user will be user as default.
174232

233+
### Category & Label Scopes
234+
| Method | Arguments | Description | Example |
235+
|---|---|---|---|
236+
| `visible` |`void` | get the visible model records | `Label::visible()->get()` |
237+
| `hidden` |`void` | get the hidden model records | `Category::visible()->get()` |
238+
175239
## Testing
176240

177241
```bash

src/Concerns/InteractsWithTickets.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function archive(): self
1616
$this->update([
1717
'status' => Status::ARCHIVED->value,
1818
]);
19+
1920
return $this;
2021
}
2122

tests/Feature/TicketTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
$this->assertTrue($ticket->isLocked());
244244
});
245245

246-
247246
it('can delete a ticket', function () {
248247
$ticket = Ticket::factory()->create();
249248

0 commit comments

Comments
 (0)