feat(User Voucher): menambahkan table pivot
This commit is contained in:
parent
7b0abd6aa2
commit
5d3deb35c3
@ -106,4 +106,9 @@ public function priceRequests(): HasMany
|
||||
{
|
||||
return $this->hasMany(PriceRequest::class);
|
||||
}
|
||||
|
||||
public function vouchers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Voucher::class);
|
||||
}
|
||||
}
|
||||
|
||||
17
app/Models/UserVoucher.php
Normal file
17
app/Models/UserVoucher.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserVoucher extends Model
|
||||
{
|
||||
protected $table = 'user_voucher';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'quantity' => 'int',
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -37,4 +37,9 @@ public function orders(): HasMany
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_voucher', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user