gpt4 book ai didi

php - SQL - 尝试在特定位置查找可用房间(laravel 4)

转载 作者:行者123 更新时间:2023-11-30 01:03:48 25 4
gpt4 key购买 nike

我正在尝试通过预订表和特定位置查找可用房间。

$not_available = Booking::where('dateFrom', '>=', $arrival)
->where('dateTo', '<=', $depart)
->get(array('gardenId', 'dateFrom', 'dateTo'));
$gardens = Garden::where('province',$location)->get();

foreach ($not_available as $not)
{
$gardenId = $not->gardenId;
$gardens = Garden::where('id','<>',$gardenId)->where('province',$location)->get();
}

我总是得到错误的结果。谁能帮帮我?

最佳答案

这应该非常接近。它是急切加载的,会给您带来更好的性能。

// If you don't have your relationships setup in your model yet.  
class Booking extends Eloquent {

public function gardens()
{
return $this->hasMany('Garden', 'gardenId');
}

}

class Garden extends Eloquent {

public $primaryKey = 'gardenId';

public function booking()
{
return $this->belongsTo('Booking');
}
}

// Eager load
$bookings = Booking::where('dateFrom', '>=', $arrival)
->where('dateTo', '<=', $depart)
->with(array('gardens' => function($query)
{
$query->where('province', '=', $location)
}))
->get();

foreach($bookings as $booking)
{
foreach($booking->gardens as $garden)
{
echo $booking->name;
echo $garden->name;
echo $garden->location;
}
}

关于php - SQL - 尝试在特定位置查找可用房间(laravel 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19858006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com