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();
i have been tried use addselect
, with closure
but same result
也许尝试将pos_id
添加到该columns数组。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.