Skip to content

Commit a2d2fd4

Browse files
committed
update README.md file
1 parent 2d4dd80 commit a2d2fd4

File tree

8 files changed

+148
-47
lines changed

8 files changed

+148
-47
lines changed

README.md

Lines changed: 143 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
# Laravel Ticket System, to help you manage to tickets eaisly, and focus on building
1+
<p align="center">
2+
<img src="art/logo.png" alt="Laravisit Logo" width="300">
3+
<br><br>
4+
</p>
25

36
[![Latest Version on Packagist](https://img.shields.io/packagist/v/coderflexx/laravel-ticket.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravel-ticket)
47
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/coderflexx/laravel-ticket/run-tests?label=tests)](https://github.com/coderflexx/laravel-ticket/actions?query=workflow%3Arun-tests+branch%3Amain)
58
[![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)
69
[![Total Downloads](https://img.shields.io/packagist/dt/coderflexx/laravel-ticket.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravel-ticket)
710

11+
12+
## Introduction
13+
__Laravel Ticket__ package, is a an Backend API to handle your ticket system, with an easy way.
14+
815
## Installation
916

1017
You can install the package via composer:
@@ -13,38 +20,157 @@ You can install the package via composer:
1320
composer require coderflex/laravel-ticket
1421
```
1522

16-
You can publish and run the migrations with:
17-
18-
```bash
19-
php artisan vendor:publish --tag="laravel-ticket-migrations"
20-
php artisan migrate
21-
```
23+
## Configuration
2224

2325
You can publish the config file with:
2426

2527
```bash
26-
php artisan vendor:publish --tag="laravel-ticket-config"
28+
php artisan vendor:publish --tag="ticket-config"
2729
```
2830

29-
This is the contents of the published config file:
31+
You can publish and run the migrations with:
3032

31-
```php
32-
return [
33-
];
33+
```bash
34+
php artisan vendor:publish --tag="ticket-migrations"
3435
```
35-
36-
Optionally, you can publish the views using
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
3737

3838
```bash
39-
php artisan vendor:publish --tag="laravel-ticket-views"
39+
php artisan migrate
4040
```
4141

4242
## Usage
4343

44+
The Basic Usage of this package, is to create a `ticket`, then associate the `labels` and the `categories` to it.
45+
46+
You can associate as many as `categories`/`labels` into a single ticket.
47+
48+
Here is an example
49+
4450
```php
45-
$laravelTicket = new Coderflex\LaravelTicket();
46-
echo $laravelTicket->echoPhrase('Hello, Coderflex!');
51+
use Coderflex\LaravelTicket\Models\Ticket;
52+
use Coderflex\LaravelTicket\Models\Category;
53+
use Coderflex\LaravelTicket\Models\Label;
54+
55+
...
56+
public function store(Request $request)
57+
{
58+
/** @var User */
59+
$user = Auth::user();
60+
61+
$ticket = $user->tickets()
62+
->create($request->validated());
63+
64+
$categories = Category::first();
65+
$labels = Label::first();
66+
67+
$ticket->attachCategories($categories);
68+
$ticket->attachLabels($labels);
69+
70+
// or you can create the categories & the tickets directly by:
71+
// $ticket->categories()->create(...);
72+
// $ticket->labels()->create(...);
73+
74+
return redirect(route('tickets.show', $ticket->uuid))
75+
->with('success', __('Your Ticket Was created successfully.'));
76+
}
77+
...
4778
```
79+
### Ticket Table Structure
80+
81+
| Column Name | Type | Default |
82+
|---|---|---|
83+
| id |`integer` | `NOT NULL` |
84+
| uuid |`string` | `NULL` |
85+
| user_id |`integer` | `NOT NULL` |
86+
| title |`string` | `NOT NULL` |
87+
| message |`string` | `NULL` |
88+
| priority |`string` | `low` |
89+
| status |`string` | `open` |
90+
| is_resolved |`boolean` | `false` |
91+
| is_locked |`boolean` | `false` |
92+
| created_at |`timestamp` | `NULL` |
93+
| updated_at |`timestamp` | `NULL` |
94+
95+
### Message Table Structure
96+
97+
| Column Name | Type | Default |
98+
|---|---|---|
99+
| id |`integer` | `NOT NULL` |
100+
| user_id |`integer` | `NOT NULL` |
101+
| ticket_id |`integer` | `NOT NULL` |
102+
| message |`string` | `NULL` |
103+
| created_at |`timestamp` | `NULL` |
104+
| updated_at |`timestamp` | `NULL` |
105+
106+
### Label Table Structure
107+
108+
| Column Name | Type | Default |
109+
|---|---|---|
110+
| id |`integer` | `NOT NULL` |
111+
| name |`string` | `NULL` |
112+
| slug |`string` | `NULL` |
113+
| is_visible |`boolean` | `false` |
114+
| created_at |`timestamp` | `NULL` |
115+
| updated_at |`timestamp` | `NULL` |
116+
117+
### Category Table Structure
118+
119+
| Column Name | Type | Default |
120+
|---|---|---|
121+
| id |`integer` | `NOT NULL` |
122+
| name |`string` | `NULL` |
123+
| slug |`string` | `NULL` |
124+
| is_visible |`boolean` | `false` |
125+
| created_at |`timestamp` | `NULL` |
126+
| updated_at |`timestamp` | `NULL` |
127+
128+
## API Methods
129+
130+
### 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__:
132+
133+
| Method | Arguments | Example | Description | Chainable |
134+
|---|---|---|---|---|
135+
| `archive` |`void` | archive the ticket | `$ticket->archive()` | ✓
136+
| `close` |`void` | close the ticket | `$ticket->close()` | ✓
137+
| `reopen` |`void` | reopen a closed ticket | `$ticket->reopen()` | ✓
138+
| `markAsResolved` |`void` | mark the ticket as resolved | `$ticket->markAsResolved()` | ✓
139+
| `markAsLocked` |`void` | mark the ticket as locked | `$ticket->markAsLocked()` | ✓
140+
| `markAsUnlocked` |`void` | mark the ticket as unlocked | `$ticket->markAsUnlocked()` | ✓
141+
| `markAsArchived` |`void` | mark the ticket as archived | `$ticket->markAsArchived()` | ✓
142+
| `closeAsResolved` |`void` | close the ticket and marked it as resolved | `$ticket->closeAsResolved()` | ✓
143+
| `closeAsUnresolved` |`void` | close the ticket and marked it as unresolved | `$ticket->closeAsUnresolved()` | ✓
144+
| `reopenAsUnresolved` |`void` | reopen the ticket and marked it as unresolved | `$ticket->reopenAsUnresolved()` | ✓
145+
| `isArchived` |`void` | check if the ticket archived | `$ticket->isArchived()` | ✗
146+
| `isOpen` |`void` | check if the ticket open | `$ticket->isOpen()` | ✗
147+
| `isClosed` |`void` | check if the ticket closed | `$ticket->isClosed()` | ✗
148+
| `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()` | ✗
150+
| `isLocked` |`void` | check if the ticket is locked | `$ticket->isLocked()` | ✗
151+
| `isUnlocked` |`void` | check if the ticket is unlocked | `$ticket->isUnlocked()` | ✗
152+
153+
The __Chainable__ column, is showing the state for the method, that if it can be chained or not, something like
154+
```php
155+
$ticket->archive()
156+
->close()
157+
->markAsResolved();
158+
```
159+
## Ticket Relashionship API Methods
160+
The `ticket` model has also a list of methods for interacting with another related models
161+
162+
| Method | Arguments | Example | Description |
163+
|---|---|---|---|
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])` |
168+
| `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')` |
170+
171+
> 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)
172+
173+
The `commentAsUser` accepts a user as a first argument, if it's null, the __authenticated__ user will be user as default.
48174

49175
## Testing
50176

art/logo.png

79.7 KB
Loading

database/migrations/create_tickets_table.php.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ return new class extends Migration
1414

1515
Schema::create($tableName, function (Blueprint $table) {
1616
$table->id();
17-
$table->uuid('uuid');
17+
$table->uuid('uuid')->nullable();
1818
$table->foreignId('user_id');
1919
$table->string('title');
2020
$table->string('message')->nullable();

src/Concerns/InteractsWithTicketRelations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function message(string $message): Model
7777
public function messageAsUser(?Model $user, string $message): Model
7878
{
7979
return $this->messages()->create([
80-
'user_id' => $user->id, // @phpstan-ignore-line
80+
'user_id' => $user?->id ?? auth()->id(), // @phpstan-ignore-line
8181
'message' => $message,
8282
]);
8383
}

src/Concerns/InteractsWithTickets.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ public function markAsUnlocked(): self
167167
*/
168168
public function markAsArchived(): self
169169
{
170-
$this->update([
171-
'status' => Status::ARCHIVED->value,
172-
]);
170+
$this->archive();
173171

174172
return $this;
175173
}
@@ -194,7 +192,7 @@ public function closeAsResolved(): self
194192
*
195193
* @return self
196194
*/
197-
public function closeAsUnResolved(): self
195+
public function closeAsUnresolved(): self
198196
{
199197
$this->update([
200198
'status' => Status::CLOSED->value,

src/Facades/LaravelTicket.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/LaravelTicket.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/Feature/TicketTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
'status' => 'open',
198198
]);
199199

200-
$ticket->closeAsUnResolved();
200+
$ticket->closeAsUnresolved();
201201

202202
$this->assertTrue($ticket->isUnresolved());
203203
$this->assertTrue($ticket->isClosed());

0 commit comments

Comments
 (0)