diff options
| author | Sam Light <samlight1994@gmail.com> | 2026-02-10 00:21:10 +0000 |
|---|---|---|
| committer | Sam Light <samlight1994@gmail.com> | 2026-02-10 00:21:10 +0000 |
| commit | ad1c06ee1819b3512e2443d5cbe06199a0ae9bad (patch) | |
| tree | b873596f86173c70c29decc301397d716ad7ca8d /workbench/app | |
| parent | 47c3c4b4e772c30dac12169300e20346fa47b71f (diff) | |
Created order tables and models
Diffstat (limited to 'workbench/app')
| -rw-r--r-- | workbench/app/Enums/OrderStatus.php | 11 | ||||
| -rw-r--r-- | workbench/app/Models/Order.php | 51 |
2 files changed, 62 insertions, 0 deletions
diff --git a/workbench/app/Enums/OrderStatus.php b/workbench/app/Enums/OrderStatus.php new file mode 100644 index 0000000..555e31a --- /dev/null +++ b/workbench/app/Enums/OrderStatus.php @@ -0,0 +1,11 @@ +<?php + +namespace Workbench\App\Enums; + +enum OrderStatus: string +{ + case Pending = 'pending'; + case Processing = 'processing'; + case Completed = 'completed'; + case Cancelled = 'cancelled'; +} 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(); + } +} |
