File tree Expand file tree Collapse file tree 5 files changed +40
-0
lines changed Expand file tree Collapse file tree 5 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,7 @@ public function createCategory()
152152| status | ` string ` | ` open ` |
153153| is_resolved | ` boolean ` | ` false ` |
154154| is_locked | ` boolean ` | ` false ` |
155+ | assigned_to_user_id | ` integer ` | ` NULL ` |
155156| created_at | ` timestamp ` | ` NULL ` |
156157| updated_at | ` timestamp ` | ` NULL ` |
157158
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ return new class extends Migration
2222 $table->string('status')->default('open');
2323 $table->boolean('is_resolved')->default(false);
2424 $table->boolean('is_locked')->default(false);
25+ $table->foreignId('assigned_to_user_id')->nullable();
2526 $table->timestamps();
2627 });
2728 }
Original file line number Diff line number Diff line change 33namespace Coderflex \LaravelTicket \Concerns ;
44
55use Coderflex \LaravelTicket \Enums \Status ;
6+ use Illuminate \Database \Eloquent \Model ;
67
78trait InteractsWithTickets
89{
@@ -216,4 +217,19 @@ public function reopenAsUnresolved(): self
216217
217218 return $ this ;
218219 }
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+ }
219235}
Original file line number Diff line number Diff line change 2222 * @property string $status
2323 * @property bool $is_resolved
2424 * @property bool $is_locked
25+ * @property int $assigned_to_user_id
2526 */
2627class Ticket extends Model
2728{
@@ -47,6 +48,16 @@ public function user(): BelongsTo
4748 return $ this ->belongsTo (User::class);
4849 }
4950
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+
5061 /**
5162 * Get Messages RelationShip
5263 *
Original file line number Diff line number Diff line change 11<?php
22
33use Coderflex \LaravelTicket \Models \Ticket ;
4+ use Coderflex \LaravelTicket \Tests \Models \User ;
45
56it ('filters tickets by status ' , function () {
67 Ticket::factory ()
250251
251252 $ this ->assertEquals (Ticket::count (), 0 );
252253});
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