Category.php 1014 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 $fillable = ['title', 'parent', 'category_type', 'creator_id', 'slug', 'discription'];
  10. use SoftDeletes;
  11. public function user()
  12. {
  13. return $this->belongsTo(User::class, 'creator_id', 'id');
  14. }
  15. public function products()
  16. {
  17. return $this->morphedByMany(Product::class, 'categorizable');
  18. }
  19. public function getCategoryTypeAttribute($value)
  20. {
  21. switch ($value) {
  22. case 0:
  23. $category_type = 'محصولات';
  24. break;
  25. case 1:
  26. $category_type = 'اخبار';
  27. break;
  28. case 2:
  29. $category_type = 'مطالب';
  30. break;
  31. default:
  32. $category_type = '';
  33. }
  34. return $category_type;
  35. }
  36. }