diff --git a/app/Models/User.php b/app/Models/User.php index e89b5be..bfab67d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -106,4 +106,9 @@ public function priceRequests(): HasMany { return $this->hasMany(PriceRequest::class); } + + public function vouchers(): BelongsToMany + { + return $this->belongsToMany(Voucher::class); + } } diff --git a/app/Models/UserVoucher.php b/app/Models/UserVoucher.php new file mode 100644 index 0000000..04f4277 --- /dev/null +++ b/app/Models/UserVoucher.php @@ -0,0 +1,17 @@ + 'int', + ]; + } +} diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index a2c0664..a3bd40a 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -37,4 +37,9 @@ public function orders(): HasMany { return $this->hasMany(Order::class); } + + public function users(): BelongsToMany + { + return $this->belongsToMany(User::class); + } } diff --git a/database/migrations/2025_10_06_135045_create_orders_table.php b/database/migrations/2025_10_06_135045_create_orders_table.php index 49363b4..7ea1175 100644 --- a/database/migrations/2025_10_06_135045_create_orders_table.php +++ b/database/migrations/2025_10_06_135045_create_orders_table.php @@ -18,7 +18,6 @@ public function up(): void $table->foreignId('outlet_id')->constrained()->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->foreignId('customer_id')->nullable()->constrained()->cascadeOnDelete(); - $table->foreignId('voucher_id')->nullable()->constrained()->cascadeOnDelete(); $table->string('invoice_number', 50); $table->unsignedInteger('cogs'); $table->unsignedInteger('subtotal'); diff --git a/database/migrations/2025_11_04_220210_create_user_voucher_table.php b/database/migrations/2025_11_04_220210_create_user_voucher_table.php new file mode 100644 index 0000000..1d9bd51 --- /dev/null +++ b/database/migrations/2025_11_04_220210_create_user_voucher_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignId('user_id')->constrained()->cascadeOnDelete(); + $table->foreignId('voucher_id')->constrained()->cascadeOnDelete(); + $table->unsignedInteger('quantity'); + $table->timestamp('created_at')->useCurrent(); + $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('user_voucher'); + } +};