File tree Expand file tree Collapse file tree 6 files changed +37
-6
lines changed Expand file tree Collapse file tree 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
227227 public function assignTo (Model |int $ user ): self
228228 {
229229 $ this ->update ([
230- 'assigned_to_user_id ' => $ user ,
230+ 'assigned_to ' => $ user ,
231231 ]);
232232
233233 return $ this ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public function configurePackage(Package $package): void
2424 'create_labels_table ' ,
2525 'create_category_ticket_table ' ,
2626 'create_label_ticket_table ' ,
27+ 'add_assigned_to_column_into_tickets_table ' ,
2728 );
2829 }
2930}
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
25+ * @property int $assigned_to
2626 */
2727class Ticket extends Model
2828{
@@ -53,9 +53,9 @@ public function user(): BelongsTo
5353 *
5454 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
5555 */
56- public function assigned_to_user (): BelongsTo
56+ public function assignedToUser (): BelongsTo
5757 {
58- return $ this ->belongsTo (User::class, 'assigned_to_user_id ' );
58+ return $ this ->belongsTo (User::class, 'assigned_to ' );
5959 }
6060
6161 /**
Original file line number Diff line number Diff line change 252252 $ this ->assertEquals (Ticket::count (), 0 );
253253});
254254
255- it ('can assign ticket to a user ' , function () {
255+ it ('can assign ticket to a user using user model ' , function () {
256256 $ ticket = Ticket::factory ()->create ();
257257 $ agentUser = User::factory ()->create ();
258258
259259 $ ticket ->assignTo ($ agentUser );
260260
261- expect ($ ticket ->assigned_to_user_id )
261+ expect ($ ticket ->assigned_to )
262262 ->toBe ($ agentUser );
263263});
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)
3535 include __DIR__ .'/../database/migrations/create_categories_table.php.stub ' ,
3636 include __DIR__ .'/../database/migrations/create_messages_table.php.stub ' ,
3737 include __DIR__ .'/../database/migrations/create_labels_table.php.stub ' ,
38+ include __DIR__ .'/../database/migrations/add_assigned_to_column_into_tickets_table.php.stub ' ,
3839
3940 // Many to Many tables
4041 include __DIR__ .'/../database/migrations/create_label_ticket_table.php.stub ' ,
You can’t perform that action at this time.
0 commit comments