Sentence.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. class Sentence extends Model
  7. {
  8. use HasFactory;
  9. use SoftDeletes;
  10. protected $fillable = [
  11. 'id',
  12. 'uid',
  13. 'book_id',
  14. 'paragraph',
  15. 'word_start',
  16. 'word_end',
  17. 'channel_uid',
  18. 'editor_uid',
  19. 'content',
  20. 'content_type',
  21. 'strlen',
  22. 'status',
  23. 'create_time',
  24. 'modify_time',
  25. 'language'
  26. ];
  27. protected $primaryKey = 'uid';
  28. protected $casts = [
  29. 'uid' => 'string',
  30. 'channel_uid' => 'string',
  31. ];
  32. protected $dates = [
  33. 'created_at',
  34. 'updated_at',
  35. 'deleted_at',
  36. 'fork_at'
  37. ];
  38. /**
  39. * 获取句子所属的频道
  40. */
  41. public function channel()
  42. {
  43. return $this->belongsTo(Channel::class, 'channel_uid', 'uid');
  44. }
  45. public function scopeNissaya($query)
  46. {
  47. return $query->whereHas('channel', function ($q) {
  48. $q->where('type', 'nissaya');
  49. });
  50. }
  51. public function scopeLanguage($query, $language)
  52. {
  53. return $query->whereHas('channel', function ($q) use ($language) {
  54. $q->where('lang', $language);
  55. });
  56. }
  57. }