Attribute.php 790 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Packages\Product\Models;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Attribute extends Model
  6. {
  7. use SoftDeletes;
  8. protected $table = 'attributes';
  9. protected $fillable=['title', 'key', 'use_in_veriation'];
  10. public function products()
  11. {
  12. return $this->morphedByMany(Product::class, 'attributable')->withPivot(['val_attribute']);
  13. }
  14. public function getUseInVeriationAttribute($value)
  15. {
  16. switch ($value) {
  17. case 0:
  18. $UseInVeriation = 'خیر';
  19. break;
  20. case 1:
  21. $UseInVeriation = 'بله';
  22. break;
  23. default:
  24. $UseInVeriation = '';
  25. }
  26. return $UseInVeriation ;
  27. }
  28. }