簡體   English   中英

Laravel所屬返回null

[英]Laravel belongsTo return null

我有兩種模式

字模型:

class Word extends Model
{
 public function pos()
    {
        return $this->belongsTo(Pos::class);
    }
}

PoS模型

class Pos extends Model
{
    //
    protected $table = 'pos';
    public $timestamps = false;
}

現在在控制器中我想獲取wordpos關系,但是當我指定列時pos關系返回null

調節器

$word = Word::with(['pos'])->whereId( $vocabulary->word_id)->get(['id', 'word', 'surface', 'gloss', 'example','sound_url'])->first();

請注意當我使用查詢而不指定列完美地工作

   $word = Word::with(['pos'])->whereId( $vocabulary->word_id)->first();

我已經嘗試過使用addselectwith closure但相同的結果

也許嘗試將pos_id添加到該columns數組。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM