diff options
Diffstat (limited to 'workbench')
| -rw-r--r-- | workbench/app/Models/Category.php | 8 | ||||
| -rw-r--r-- | workbench/app/Models/Product.php | 21 |
2 files changed, 29 insertions, 0 deletions
diff --git a/workbench/app/Models/Category.php b/workbench/app/Models/Category.php index 8e30c31..28b08de 100644 --- a/workbench/app/Models/Category.php +++ b/workbench/app/Models/Category.php @@ -5,8 +5,16 @@ namespace Workbench\App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Carbon; use Workbench\Database\Factories\CategoryFactory; +/** + * @property int $id + * @property string $name + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + */ class Category extends Model { /** diff --git a/workbench/app/Models/Product.php b/workbench/app/Models/Product.php index a44cb03..e5e6bcb 100644 --- a/workbench/app/Models/Product.php +++ b/workbench/app/Models/Product.php @@ -6,8 +6,21 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Support\Carbon; use Workbench\Database\Factories\ProductFactory; +/** + * @property int $id + * @property string $name + * @property string $description + * @property string $price + * @property int $stock + * @property int $category_id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + */ class Product extends Model { /** @@ -42,4 +55,12 @@ class Product extends Model { return $this->belongsTo(Category::class); } + + /** + * @return BelongsToMany<Order, $this> + */ + public function orders(): BelongsToMany + { + return $this->belongsToMany(Order::class)->withPivot('quantity', 'price')->withTimestamps(); + } } |
