Add Cart model, resource and its API, Pivot table with Items.
Update Items model to have relationship with cart.
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
@@ -23,4 +24,10 @@ class Item extends Model
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function carts(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Cart::class, 'carts_items', 'item_id', 'cart_id');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user