File tree 6 files changed +37
-6
lines changed
6 files changed +37
-6
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Coderflex\LaravelTicket\Database\Factories;
4
+
5
+ use Illuminate\Database\Migrations\Migration;
6
+ use Illuminate\Database\Schema\Blueprint;
7
+ use Illuminate\Support\Facades\Schema;
8
+
9
+ return new class extends Migration
10
+ {
11
+ public function up()
12
+ {
13
+ $tableName = config('laravel_ticket.table_names.tickets', 'tickets');
14
+
15
+ Schema::table($tableName, function (Blueprint $table) {
16
+ $table->unsignedBigInteger('assigned_to')->nullable()->references('id')->on('users')->after('is_locked');
17
+ });
18
+ }
19
+ };
Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ public function reopenAsUnresolved(): self
227
227
public function assignTo (Model |int $ user ): self
228
228
{
229
229
$ this ->update ([
230
- 'assigned_to_user_id ' => $ user ,
230
+ 'assigned_to ' => $ user ,
231
231
]);
232
232
233
233
return $ this ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public function configurePackage(Package $package): void
24
24
'create_labels_table ' ,
25
25
'create_category_ticket_table ' ,
26
26
'create_label_ticket_table ' ,
27
+ 'add_assigned_to_column_into_tickets_table ' ,
27
28
);
28
29
}
29
30
}
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
+ * @property int $assigned_to
26
26
*/
27
27
class Ticket extends Model
28
28
{
@@ -53,9 +53,9 @@ public function user(): BelongsTo
53
53
*
54
54
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
55
55
*/
56
- public function assigned_to_user (): BelongsTo
56
+ public function assignedToUser (): BelongsTo
57
57
{
58
- return $ this ->belongsTo (User::class, 'assigned_to_user_id ' );
58
+ return $ this ->belongsTo (User::class, 'assigned_to ' );
59
59
}
60
60
61
61
/**
Original file line number Diff line number Diff line change 252
252
$ this ->assertEquals (Ticket::count (), 0 );
253
253
});
254
254
255
- it ('can assign ticket to a user ' , function () {
255
+ it ('can assign ticket to a user using user model ' , function () {
256
256
$ ticket = Ticket::factory ()->create ();
257
257
$ agentUser = User::factory ()->create ();
258
258
259
259
$ ticket ->assignTo ($ agentUser );
260
260
261
- expect ($ ticket ->assigned_to_user_id )
261
+ expect ($ ticket ->assigned_to )
262
262
->toBe ($ agentUser );
263
263
});
264
+
265
+ it ('can assign ticket to a user using user id ' , function () {
266
+ $ ticket = Ticket::factory ()->create ();
267
+ $ agentUser = User::factory ()->create ();
268
+
269
+ $ ticket ->assignTo ($ agentUser ->id );
270
+
271
+ expect ($ ticket ->assigned_to )
272
+ ->toBe ($ agentUser ->id );
273
+ });
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public function getEnvironmentSetUp($app)
35
35
include __DIR__ .'/../database/migrations/create_categories_table.php.stub ' ,
36
36
include __DIR__ .'/../database/migrations/create_messages_table.php.stub ' ,
37
37
include __DIR__ .'/../database/migrations/create_labels_table.php.stub ' ,
38
+ include __DIR__ .'/../database/migrations/add_assigned_to_column_into_tickets_table.php.stub ' ,
38
39
39
40
// Many to Many tables
40
41
include __DIR__ .'/../database/migrations/create_label_ticket_table.php.stub ' ,
You can’t perform that action at this time.
0 commit comments