我在酒店模特
中有自定义功能public function images()
{
return $this->hasMany('App\HotelImage', 'hotel_id', 'id');
}
public function translate(){
$hotel = $this->translates->where('lang',app()->getLocale())->first();
return $hotel ? $hotel : $this;
}
在我的api控制器中我返回响应() - > json($ hotels);
1. $hotels = Hotel::with('images')->where(function($query) use($q){
foreach($q as $price){
$query->orWhereBetween( 'price', explode(',',$price) );
}
})->get();
2. $hotels = Hotel::with('translate')->where(function($query) use($q){
foreach($q as $price){
$query->orWhereBetween( 'price', explode(',',$price) );
}
})->get();
1 - 正在运作
输出
id:2,
images:[{id: 3, name: "1505464164_5.jpg", size: 270617, hotel_id: 2}]
name:"test2"
phone:"556464"
place:"Baku, Azerbaijan"
2 - 无效输出
Call to undefined method Illuminate\Database\Query\Builder::addEagerConstraints()