Category.php 893 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Repositories\Models\Course;
  3. use App\Repositories\Models\Model;
  4. use Prettus\Repository\Contracts\Transformable;
  5. use Prettus\Repository\Traits\TransformableTrait;
  6. /**
  7. * Class CourseCategory.
  8. *
  9. * @package namespace App\Repositories\Models;
  10. */
  11. class Category extends Model implements Transformable
  12. {
  13. use TransformableTrait;
  14. protected $table = 'course_categories';
  15. /**
  16. * The attributes that are mass assignable.
  17. *
  18. * @var array
  19. */
  20. protected $fillable = ['name', 'parent_id', 'sort', 'status'];
  21. protected static function booted()
  22. {
  23. self::language();
  24. }
  25. public function parent()
  26. {
  27. return $this->belongsTo(Category::class, 'parent_id', 'id');
  28. }
  29. public function getParentNameAttribute()
  30. {
  31. return self::query()->where('id', $this->attributes['parent_id'])->value('name');
  32. }
  33. }