diff options
Diffstat (limited to 'workbench/app/Models/Order.php')
| -rw-r--r-- | workbench/app/Models/Order.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/workbench/app/Models/Order.php b/workbench/app/Models/Order.php new file mode 100644 index 0000000..84a13ab --- /dev/null +++ b/workbench/app/Models/Order.php @@ -0,0 +1,51 @@ +<?php + +namespace Workbench\App\Models; + +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Support\Carbon; +use Workbench\App\Enums\OrderStatus; +use Workbench\Database\Factories\OrderFactory; + +/** + * @property int $id + * @property OrderStatus $status + * @property string $total + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + */ +class Order extends Model +{ + /** + * @use HasFactory<OrderFactory> + */ + use HasFactory; + + /** + * @return OrderFactory<static> + */ + protected static function newFactory(): OrderFactory + { + return OrderFactory::new(); + } + + /** + * @return array<string, string> + */ + protected function casts(): array + { + return [ + 'status' => OrderStatus::class, + ]; + } + + /** + * @return BelongsToMany<Product, $this> + */ + public function products(): BelongsToMany + { + return $this->belongsToMany(Product::class)->withPivot('quantity', 'price')->withTimestamps(); + } +} |
