Răsfoiți Sursa

add channel scopeNissaya scopeLanguage

visuddhinanda 3 luni în urmă
părinte
comite
b489d0d97c
1 a modificat fișierele cu 40 adăugiri și 5 ștergeri
  1. 40 5
      api-v8/app/Models/Sentence.php

+ 40 - 5
api-v8/app/Models/Sentence.php

@@ -10,13 +10,27 @@ class Sentence extends Model
 {
     use HasFactory;
     use SoftDeletes;
-	protected $fillable = ['id','uid','book_id',
-                          'paragraph','word_start','word_end',
-                          'channel_uid','editor_uid','content','content_type',
-                          'strlen','status','create_time','modify_time','language'];
+    protected $fillable = [
+        'id',
+        'uid',
+        'book_id',
+        'paragraph',
+        'word_start',
+        'word_end',
+        'channel_uid',
+        'editor_uid',
+        'content',
+        'content_type',
+        'strlen',
+        'status',
+        'create_time',
+        'modify_time',
+        'language'
+    ];
     protected $primaryKey = 'uid';
     protected $casts = [
-        'uid' => 'string'
+        'uid' => 'string',
+        'channel_uid' => 'string',
     ];
 
     protected $dates = [
@@ -26,4 +40,25 @@ class Sentence extends Model
         'fork_at'
     ];
 
+    /**
+     * 获取句子所属的频道
+     */
+    public function channel()
+    {
+        return $this->belongsTo(Channel::class, 'channel_uid', 'uid');
+    }
+
+    public function scopeNissaya($query)
+    {
+        return $query->whereHas('channel', function ($q) {
+            $q->where('type', 'nissaya');
+        });
+    }
+
+    public function scopeLanguage($query, $language)
+    {
+        return $query->whereHas('channel', function ($q) use ($language) {
+            $q->where('lang', $language);
+        });
+    }
 }