Category.php 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Repositories\Models\TCM;
  3. use App\Repositories\Models\Model;
  4. use Prettus\Repository\Contracts\Transformable;
  5. use Prettus\Repository\Traits\TransformableTrait;
  6. /**
  7. * Class Category.
  8. *
  9. * @package namespace App\Repositories\Models\TCM;
  10. */
  11. class Category extends Model implements Transformable
  12. {
  13. use TransformableTrait;
  14. protected $table = 'tcm_categories';
  15. /**
  16. * The attributes that are mass assignable.
  17. *
  18. * @var array
  19. */
  20. protected $guarded = [];
  21. protected static function booted()
  22. {
  23. self::language();
  24. }
  25. public static function byIdGetCategoryValue($id)
  26. {
  27. return self::query()->where('id', $id)->value('title');
  28. }
  29. public static function byIdsGetCategoryValue($ids)
  30. {
  31. return self::query()->whereIn('id', $ids)->pluck('title')->toArray();
  32. }
  33. public function getParentNameAttribute()
  34. {
  35. return self::query()->where('id', $this->attributes['parent_id'])->value('title') ?? '--';
  36. }
  37. }