feat(purchase): menambahkan kolom user_id dan menyesuaikan relasinya
This commit is contained in:
parent
100aff8403
commit
912e6c2d37
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -23,11 +25,22 @@ protected function casts(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Scope]
|
||||||
|
public function currentUser(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('user_id', auth()->id());
|
||||||
|
}
|
||||||
|
|
||||||
public function purchase(): BelongsTo
|
public function purchase(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Purchase::class);
|
return $this->belongsTo(Purchase::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function purchasable(): MorphTo
|
public function purchasable(): MorphTo
|
||||||
{
|
{
|
||||||
return $this->morphTo();
|
return $this->morphTo();
|
||||||
|
|||||||
@ -92,6 +92,11 @@ public function orderItems(): HasMany
|
|||||||
return $this->hasMany(OrderItem::class);
|
return $this->hasMany(OrderItem::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function purchaseItems(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(PurchaseItem::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function payments(): HasMany
|
public function payments(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Payment::class);
|
return $this->hasMany(Payment::class);
|
||||||
|
|||||||
@ -14,6 +14,7 @@ public function up(): void
|
|||||||
Schema::create('purchase_items', function (Blueprint $table) {
|
Schema::create('purchase_items', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('purchase_id')->nullable()->constrained()->cascadeOnDelete();
|
$table->foreignId('purchase_id')->nullable()->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
$table->morphs('purchasable');
|
$table->morphs('purchasable');
|
||||||
$table->unsignedInteger('quantity');
|
$table->unsignedInteger('quantity');
|
||||||
$table->unsignedInteger('unit_price');
|
$table->unsignedInteger('unit_price');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user