StoreItem.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use App\Enums\StoreItemStatusEnum;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. class StoreItem extends Model
  9. {
  10. use SoftDeletes;
  11. protected $guarded = ['id'];
  12. protected function casts(): array
  13. {
  14. return [
  15. 'price' => 'float',
  16. 'associate_price' => 'float',
  17. 'supplier_price' => 'float',
  18. 'size_s' => 'boolean',
  19. 'size_m' => 'boolean',
  20. 'size_l' => 'boolean',
  21. 'size_xl' => 'boolean',
  22. 'stock_s' => 'integer',
  23. 'stock_m' => 'integer',
  24. 'stock_l' => 'integer',
  25. 'stock_xl' => 'integer',
  26. 'status' => StoreItemStatusEnum::class,
  27. ];
  28. }
  29. public function category(): BelongsTo
  30. {
  31. return $this->belongsTo(Category::class);
  32. }
  33. public function interests(): HasMany
  34. {
  35. return $this->hasMany(StoreItemInterest::class);
  36. }
  37. public function media(): HasMany
  38. {
  39. return $this->hasMany(Media::class, 'source_id')->where('source', 'store_item');
  40. }
  41. }