0
我有以下連接2個模型的函數。Laravel Eloquent不返回連接表
$listing = Game::where('status', '2')->whereHas('transaction', function ($query) use($id) {
$query->where('status',1)->where('transaction_id', Crypt::decrypt($id));
})->get();
我有了下面的代碼遊戲模型。
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');
}
我也有具有以下代碼GameTransaction模型。
protected $table = 'game_transactions';
protected $primaryKey = 'id';
protected $fillable = ['listing_id', 'transaction_id', 'payee_id'];
protected $dates = ['deleted_at'];
我遇到的問題是$listing
變量只從game_transactions
表返回從game_listings
表中的數據,並沒有什麼。
非常感謝!儘管你在'with'語句中有一點拼寫錯誤,它的工作很完美。 – Curtis
@Curtis沒問題 –