Note.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Repositories\Models\Note;
  3. use App\Repositories\Models\Course\Category;
  4. use App\Repositories\Models\Model;
  5. use App\Repositories\Models\User\User;
  6. use Prettus\Repository\Contracts\Transformable;
  7. use Prettus\Repository\Traits\TransformableTrait;
  8. /**
  9. * Class Note.
  10. *
  11. * @package namespace App\Repositories\Models\Note;
  12. */
  13. class Note extends Model implements Transformable
  14. {
  15. use TransformableTrait;
  16. const RELEASED_RAFT = 0;
  17. const RELEASED_ISSUE = 1;
  18. protected $table = 'node_notes';
  19. /**
  20. * The attributes that are mass assignable.
  21. *
  22. * @var array
  23. */
  24. protected $guarded = [];
  25. protected static function booted()
  26. {
  27. self::language();
  28. }
  29. public function user()
  30. {
  31. return $this->belongsTo(User::class)->select(['name', 'headimg']);
  32. }
  33. public function setTagsAttribute($val)
  34. {
  35. if (count($val) == 0) return '';
  36. $this->attributes['tags'] = '-' . arr2str($val, '-') . '-';
  37. }
  38. public function getTagsAttribute($val)
  39. {
  40. return str2arr(trim($val, '-'), '-');
  41. }
  42. public function category()
  43. {
  44. return $this->belongsTo(Category::class, 'course_category_id', 'id')->select(['name']);
  45. }
  46. }