Category.php 888 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Models;
  3. use App\User;
  4. use Packages\Product\Models\Product;;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. class Category extends Model
  8. {
  9. protected $guarded = [] ;
  10. use SoftDeletes;
  11. public function user()
  12. {
  13. return $this->belongsTo(User::class, 'creator_id', 'id');
  14. }
  15. public function category()
  16. {
  17. return $this->morphedByMany('Packages\Product\Models', 'categorizable');
  18. }
  19. public function getTypeAttribute($value)
  20. {
  21. switch ($value) {
  22. case 0:
  23. $type= 'ساده';
  24. break;
  25. case 1:
  26. $type= 'متغیر';
  27. break;
  28. case 2:
  29. $type= 'باندل';
  30. break;
  31. default:
  32. $type='';
  33. }
  34. return $type;
  35. }
  36. }