adding a cart
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
2026-04-10 08:54:20 -06:00
parent ebf30d4f5f
commit d9cb44e93c
16 changed files with 559 additions and 39 deletions
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Database\Factories\CartFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Cart extends Model
{
/** @use HasFactory<CartFactory> */
use HasFactory;
protected $fillable = ['user_id'];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class)->withPivot('quantity');
}
}
+6
View File
@@ -7,6 +7,7 @@ use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
@@ -18,6 +19,11 @@ class User extends Authenticatable
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable, TwoFactorAuthenticatable;
public function cart(): HasOne
{
return $this->hasOne(Cart::class);
}
/**
* Get the attributes that should be cast.
*