File tree 5 files changed +40
-0
lines changed
5 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,7 @@ public function createCategory()
152
152
| status | ` string ` | ` open ` |
153
153
| is_resolved | ` boolean ` | ` false ` |
154
154
| is_locked | ` boolean ` | ` false ` |
155
+ | assigned_to_user_id | ` integer ` | ` NULL ` |
155
156
| created_at | ` timestamp ` | ` NULL ` |
156
157
| updated_at | ` timestamp ` | ` NULL ` |
157
158
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ return new class extends Migration
22
22
$table->string('status')->default('open');
23
23
$table->boolean('is_resolved')->default(false);
24
24
$table->boolean('is_locked')->default(false);
25
+ $table->foreignId('assigned_to_user_id')->nullable();
25
26
$table->timestamps();
26
27
});
27
28
}
Original file line number Diff line number Diff line change 3
3
namespace Coderflex \LaravelTicket \Concerns ;
4
4
5
5
use Coderflex \LaravelTicket \Enums \Status ;
6
+ use Illuminate \Database \Eloquent \Model ;
6
7
7
8
trait InteractsWithTickets
8
9
{
@@ -216,4 +217,19 @@ public function reopenAsUnresolved(): self
216
217
217
218
return $ this ;
218
219
}
220
+
221
+ /**
222
+ * Add new message on an existing ticket as a custom user
223
+ *
224
+ * @param \Illuminate\Database\Eloquent\Model|int $user
225
+ * @return self
226
+ */
227
+ public function assignTo (Model |int $ user ): self
228
+ {
229
+ $ this ->update ([
230
+ 'assigned_to_user_id ' => $ user ,
231
+ ]);
232
+
233
+ return $ this ;
234
+ }
219
235
}
Original file line number Diff line number Diff line change 22
22
* @property string $status
23
23
* @property bool $is_resolved
24
24
* @property bool $is_locked
25
+ * @property int $assigned_to_user_id
25
26
*/
26
27
class Ticket extends Model
27
28
{
@@ -47,6 +48,16 @@ public function user(): BelongsTo
47
48
return $ this ->belongsTo (User::class);
48
49
}
49
50
51
+ /**
52
+ * Get Assigned To User RelationShip
53
+ *
54
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
55
+ */
56
+ public function assigned_to_user (): BelongsTo
57
+ {
58
+ return $ this ->belongsTo (User::class, 'assigned_to_user_id ' );
59
+ }
60
+
50
61
/**
51
62
* Get Messages RelationShip
52
63
*
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use Coderflex \LaravelTicket \Models \Ticket ;
4
+ use Coderflex \LaravelTicket \Tests \Models \User ;
4
5
5
6
it ('filters tickets by status ' , function () {
6
7
Ticket::factory ()
250
251
251
252
$ this ->assertEquals (Ticket::count (), 0 );
252
253
});
254
+
255
+ it ('can assign ticket to a user ' , function () {
256
+ $ ticket = Ticket::factory ()->create ();
257
+ $ agentUser = User::factory ()->create ();
258
+
259
+ $ ticket ->assignTo ($ agentUser );
260
+
261
+ expect ($ ticket ->assigned_to_user_id )
262
+ ->toBe ($ agentUser );
263
+ });
You can’t perform that action at this time.
0 commit comments