Я разрабатываю функциональность фильтрации в своем приложении и хочу применить условие where к результату union, и я попытался таким образом, но он не работает.
$pricePerHour = VenueInfo::whereBetween("pricePerHour", [$values[0], $values[1] ]);
$pricePerDay = VenueInfo::whereBetween("pricePerDay", [$values[0], $values[1] ])->union($pricePerHour);
$result = DB::table(DB::raw("({$pricePerDay->toSql()}) as price"))
->mergeBindings($pricePerDay->getQuery())
->selectRaw("price.*")
->where('price.city' ,'Karachi');
Я ничего не получаю в
dd($result->get());
когда я получу $ result, я должен применить фильтры к $ result как:
$venues = $result->when($spaceType, function($query, $spaceType){
$query->where('spaceType', $spaceType);
})
Я тоже так пробовал.
$pricePerHour = DB::table('venue_infos')->whereRaw(("pricePerHour between $values[0] and $values[1] "));
$pricePerDay = DB::table('venue_infos')->whereRaw(("pricePerDay between $values[0] and $values[1]"))->union($pricePerHour);
$result = DB::table(DB::raw("({$pricePerDay->toSql()}) as price"))
->mergeBindings($pricePerDay);
но здесь проблема в том, когда я делаю
dd($result->get()[0]->images);
выдает ошибку:
Undefined property: stdClass::$images
здесь таблица venue_infos имеет отношение один ко многим с таблицей изображений.
public function venueInfo(){
return $this->belongsTo('App\VenueInfo','d_id');
}
public function images(){
return $this->hasMany('App\Image', 'd_id', 'daftar_id');
}