这是我页面的控制器。
创建一个新的控制器实例。 @return无效 公共函数__construct(){} 显示应用程序仪表板。 @return回复
class listingController extends Controller {
public function listing($cate) { // change tha micedias ti venue
$record = DB::table('venues')
->join('uploads', 'venues.image', '=', 'uploads.id')
->join('hotels', 'venues.hotel_name', '=', 'hotels.id')
->join('categories', 'venues.ideal_for', '=', 'categories.id')
->where('hotels.deleted_at', '=', NULL)
->where('categories.category_name', '=', $cate)
->orderBy('venues.id', 'desc')
->select('uploads.name as photo', 'uploads.hash', 'hotels.*')
->get();
$location = DB::table('venues')
->join('hotels', 'venues.hotel_name', '=', 'hotels.id')
->join('categories', 'venues.ideal_for', '=', 'categories.id')
->where('categories.category_name', '=', $cate)
->where('hotels.deleted_at', '=', NULL)
->groupBy('hotels.city_name')
->select('hotels.city_name', DB::raw('COUNT(hotels.city_name) as city_count'))
->get();
$category = DB::table('categories')
->select('categories.*')
->get();
$mainaddress = DB::table('contacts')
->select('contacts.*')
->orderBy('id', 'desc')
->limit(1)
->get();
$facilities = DB::table('facilities')
->where('deleted_at', '=', NULL)
->select('facilities.*')
->get();
return view('listing', ['record' => $record, 'location' => $location, 'cate' => $cate, 'category' => $category, 'mainaddress' => $mainaddress, 'facilities' => $facilities]);
}
public function searchData(Request $request) {
$record = DB::table('hotels')
->join('uploads', 'hotels.image', '=', 'uploads.id')
->where('hotels.location_slug', '=', $request->location)
->where('hotels.deleted_at', '=', NULL)
->orderBy('hotels.id', 'desc')
->select('uploads.name as photo', 'uploads.hash', 'hotels.*')
->get();
$location = DB::table('hotels')
->Where('location_slug', '=', $request->location)
->where('deleted_at', '=', NULL)
->groupBy('city_name')
->select('location_slug','city_name', DB::raw('COUNT(city_name) as city_count'))
->get();
$facilities = DB::table('facilities')
->where('deleted_at', '=', NULL)
->select('facilities.*')
->get();
$category = DB::table('categories')
->select('categories.*')
->get();
$mainaddress = DB::table('contacts')
->select('contacts.*')
->orderBy('id', 'desc')
->limit(1)
->get();
return view('search_listing', ['record' => $record, 'location' => $location, 'cate' => $request->location, 'facilities' => $facilities, 'category' => $category, 'mainaddress' => $mainaddress]);
}
public function getAjaxListing(Request $request) {
// $ data = DB :: table('hotels')//
- > join('uploads','hotels.image','=','uploads.id')// // - > when($ request-> location,function($ query)使用 ($ request){//返回 $ query-> whereIn('hotels.city_name',$ request-> location); //
})// - > groupBy('hotels.hotel_name')//
- >选择('hotels。*','uploads.name as photo','uploads.hash')// - > get();
$data = DB::table('hotels')
->join('uploads', 'hotels.image', '=', 'uploads.id')
->leftJoin('hotel_facilities', 'hotels.id', '=', 'hotel_facilities.hotel_id')
->leftJoin('facilities', 'hotel_facilities.facility_id', '=', 'facilities.id')
->leftJoin('venues', 'hotels.id', '=', 'venues.hotel_name')
->when($request->service, function($query) use ($request) {
return $query->whereIn('facilities.facility_name', $request->service);
})
->when($request->location, function($query) use ($request) {
return $query->whereIn('hotels.city_name', $request->location);
})
->groupBy('hotels.id')
->select('hotels.*', 'uploads.name as photo', 'uploads.hash')
->get();
return response()->json(['data' => $data]);
}
public function getAjaxListingsearch(Request $request) {
$data = DB::table('hotels')
->join('uploads', 'hotels.image', '=', 'uploads.id')
->leftJoin('hotel_facilities', 'hotels.id', '=', 'hotel_facilities.hotel_id')
->leftJoin('facilities', 'hotel_facilities.facility_id', '=', 'facilities.id')
->leftJoin('venues', 'hotels.id', '=', 'venues.hotel_name')
->when($request->service, function($query) use ($request) {
return $query->whereIn('facilities.facility_name', $request->service);
})
->when($request->location, function($query) use ($request) {
return $query->whereIn('hotels.location_slug', $request->location);
})
->groupBy('hotels.id')
->select('hotels.*', 'uploads.name as photo', 'uploads.hash')
->get();
return response()->json(['data' => $data]);
}
}