Laravel 要求一个有说服力的结构或其他方式
你好,, 我想征求你的意见。如你所见,我有这些表的结构。我想预订一个有内容的房间。但在我的结构中,我无法获得真正的数据 对于订单id-1,我得到-> 预订id 1资源名称\u 1 预订id 2 res_name_2(代替额外id 2) 我希望,我解释清楚了 致以最良好的祝愿Laravel 要求一个有说服力的结构或其他方式,laravel,eloquent,Laravel,Eloquent,你好,, 我想征求你的意见。如你所见,我有这些表的结构。我想预订一个有内容的房间。但在我的结构中,我无法获得真正的数据 对于订单id-1,我得到-> 预订id 1资源名称\u 1 预订id 2 res_name_2(代替额外id 2) 我希望,我解释清楚了 致以最良好的祝愿 穆拉特 假设您有一个订单模型,并且您在其中与预订模型建立了关系: $orderId = 1; // Get just the reservation for the order $reservation = Order::
穆拉特 假设您有一个
订单
模型,并且您在其中与预订
模型建立了关系:
$orderId = 1;
// Get just the reservation for the order
$reservation = Order::find($orderId)->reservation;
// Get the order and the reservation.
$reservation = Order::find($orderId)->with(['reservation'])->get();
另一个进一步的假设是您在订单
模型中的关系与预订
模型的关系如下所示:
/**
* Get the reservation record associated with the order.
*/
public function reservation()
{
return $this->hasOne('App\Reservation');
}
另一个假设是通过迁移在数据库orders表中设置外键
$table->foreign('reservation_id')->references('id')->on('reservations');
您的问题在代码方面非常模糊,只能用未知的假设来回答