你好,我想问你的建议。如您所见,我具有这些表结构。我想预定内容。但是在我的结构中,我无法获得真正的数据。
对于order_id-我得到1->保留ID 1 res_name_1预留ID 2 res_name_2(而不是额外的ID 2)
我希望,我清楚地解释了。
最好的问候。
Murat。
假设您有一个Order
模型,并且在其中建立了与Reservation
模型的关系:
$orderId = 1;
Order::findOrFail($orderId)->reservation;
另一个进一步的假设是您在Order
模型中的关系与Reservation
模型的关系如下所示:
/**
* Get the reservation record associated with the order.
*/
public function reservation()
{
return $this->hasOne('App\Reservation');
}
另一个假设是您通过迁移在数据库订单表中设置了外键。
$table->foreign('reservation_id')->references('id')->on('reservations');
https://laravel.com/docs/master/eloquent#defining-models
https://laravel.com/docs/master/eloquent-relationships
https://laravel.com/docs/master/eloquent-relationships#one-to-one
https://laravel.com/docs/master/migrations#foreign-key-constraints
您的问题对于您的代码用途非常含糊,只能在未知的假设下回答。