Note.php 1.4 KB

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