Reputation: 11
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)
Upvotes: 0
Views: 497
Reputation: 11
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. ;)
Upvotes: 1