php - Laravel Eloquent not returning join table -


i have following function joins 2 models.

$listing = game::where('status', '2')->wherehas('transaction', function ($query) use($id) {     $query->where('status',1)->where('transaction_id', crypt::decrypt($id)); })->get(); 

i have game model has following code.

protected $table = 'game_listings'; protected $primarykey = 'id'; protected $fillable = ['user_id','asset_id','trade_id','market_name','name','picture','description','price','status','clicks']; protected $dates = ['deleted_at'];  /* |-------------------------------------------------------------------------- | relations |-------------------------------------------------------------------------- */ public function user() {     return $this->belongsto('app\models\user'); }  public function transaction() {      return $this->hasone('app\models\gametransaction','listing_id','id'); } 

i have gametransaction model has following code.

protected $table = 'game_transactions'; protected $primarykey = 'id'; protected $fillable = ['listing_id', 'transaction_id', 'payee_id']; protected $dates = ['deleted_at']; 

the problem i'm having $listing variable returning data game_listings table, , nothing game_transactions table.

wherehas doesn't load relations. should use with this. try:

   game::where('status', '2')->wherehas('transaction', function ($query) use($id) {     $query->where('status',1)->where('transaction_id', crypt::decrypt($id)); })->with('transaction')->get() 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -