jeudi 25 mai 2017

Laravel belongTo return null

i have two model

Word Model:

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

and PoS Model:

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

now in controller i want to get word and pos relationship but pos relationship return null when i specify the columns

Controller

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

note when i use query without specify the columns work perfectly

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



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rkTjyw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire