简体   繁体   中英

Booking in MySQL and Laravel

I have problem with listing reservation who has more than one reservation and I don't what to this apartment be listed.

$show_apartments = DB::table('apartments')
  ->join('reservation', 'unos_id', '=', 'reservation.id_nekretnina')
  ->select('unos_id as link', 'title', 'description', 'picture', 'slug',               'max_person','reservation.dolazak','reservation.odlazak')
  ->whereNotBetween('dolazak', [$in_sql, $out_sql]) 
  // this is date check in and check out in search field
  ->whereNotBetween('odlazak', [$in_sql, $out_sql]) 
  // this is date check in and check out in search field
  ->get();

All apartments list very well but problem is when some apartment is more than one different date reservation then apartment is listed but I want only if apartment is in this range is free. I tray 50h and didn't look the solution.

When someone help me I will put this in stored procedure.

I know what is problem but I don't know to write code for this. (if in some ID_APARTMENT has this date range then don't show me this Apartment, rest yes)

I found answer. Need to use ->whereBetween - then in other query use ->whereNotIn result from first query.

It's easy now but i lost one week for this. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM