Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5中的子关系?_Php_Laravel_Relationship - Fatal编程技术网

Php Laravel 5中的子关系?

Php Laravel 5中的子关系?,php,laravel,relationship,Php,Laravel,Relationship,目前我有3种型号,上市、报价和付款,它们之间有以下关系: 上市 提议 付款 class Payment extends Model { public function offer() { return $this->belongsTo(\App\Models\Offer::class, 'item_id', 'id')->withTrashed(); } } 如何从它们的列表模型出发,直接返回与payments表的关系 挂牌可以有无限数量的优惠,

目前我有3种型号,上市、报价和付款,它们之间有以下关系:

上市

提议

付款

class Payment extends Model {

    public function offer() {
        return $this->belongsTo(\App\Models\Offer::class, 'item_id', 'id')->withTrashed();
    }

}
如何从它们的列表模型出发,直接返回与payments表的关系

挂牌可以有无限数量的优惠,但优惠最多只能有1笔付款

要查找任何相应的付款信息,我必须根据模型中的列表id查询报价,然后访问报价->付款,而我更希望这样做:

$transaction_id = $id;

$listing = Listing::whereHas('payment', function($q) use ($id) {
        $q->where('transaction_id', $id);
        $q->where('user_id', Auth::user()->id);
})->first();
使用:


为此,我尝试使用以下内容,但似乎失败了&没有返回rowsHow您使用它吗?$listing=listing::where has'payments',function$q use$id{$q->where'payments.user\u id',Auth::user->id;$q->where'payments.transaction\u id',Crypt::decrypt$id;}->first;这就是我试图使用它的方式?请首先用toSql替换并发布结果。选择*从存在的列表中选择*从支付中加入提供的内部提供。id=payments.item_id其中offers.deleted_at为空,listings.id=offers.listing_id和payments.user_id='3'和payments.transaction_id='69D20243XW764905K'和offers.deleted_at为null,payments.item_type='App\Models\Offer'和payments.status='1'和listings.deleted_at为null limit 1我已逐个检查了每个条件,它们似乎都有效吗?尽管手动运行此查询会返回0个结果
class Payment extends Model {

    public function offer() {
        return $this->belongsTo(\App\Models\Offer::class, 'item_id', 'id')->withTrashed();
    }

}
$transaction_id = $id;

$listing = Listing::whereHas('payment', function($q) use ($id) {
        $q->where('transaction_id', $id);
        $q->where('user_id', Auth::user()->id);
})->first();
public function payments() {
    return $this->hasManyThrough(Payment::class, Offer::class, null, 'item_id')
        ->where('payments.item_type', Offer::class)
        ->where('payments.status', '1')
        ->orderBy('offers.created_at', 'desc');
}