Product.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Packages\Product\Models;
  3. use App\Models\Category;
  4. use App\Models\Upload;
  5. use Illuminate\Database\Eloquent\Model;
  6. use App\User;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. class Product extends Model
  9. {
  10. use SoftDeletes;
  11. protected $fillable = ['title', 'discription', 'price', 'creator_id', 'type', 'status', 'sale_price', 'sku', 'slug'];
  12. //protected $guarded = [];
  13. public function user()
  14. {
  15. return $this->belongsTo(User::class, 'creator_id', 'id');
  16. }
  17. public function categories()
  18. {
  19. return $this->morphToMany(Category::class, 'categorizable');
  20. }
  21. public function uploads()
  22. {
  23. return $this->morphToMany('App\Models\Upload', 'uploadables');
  24. }
  25. public function getTypeAttribute($value)
  26. {
  27. switch ($value) {
  28. case 0:
  29. $type = 'ساده';
  30. break;
  31. case 1:
  32. $type = 'متغیر';
  33. break;
  34. case 2:
  35. $type = 'باندل';
  36. break;
  37. default:
  38. $type = '';
  39. }
  40. return $type;
  41. }
  42. public function getStatusAttribute($value)
  43. {
  44. switch ($value) {
  45. case 0:
  46. $type = 'ناموجود';
  47. break;
  48. case 1:
  49. $type = 'موجود';
  50. break;
  51. default:
  52. $type = '';
  53. }
  54. return $type;
  55. }
  56. }