FareedR
5 months ago

Achieve available venue on that date.

Posted 5 months ago by FareedR

i try to achieve "mini stadium" but collection still appear "stadium" and "mini stadium". should i use first() or get() ? or my query are wrong ? anyone can show me ?

database 
Venue
id | name |
1   stadium
2   mini stadium

Venue_has_bookings
id | venue_id | start_date | end_date|
1   1          2019-04-21   2019-04-25

controller
$startDate = 2019-04-21;
        $endDate = 2019-04-25;
        $availableVenue = Venue::with(['bookings' => function ($query) use ($startDate,$endDate){
            $query->where('endDate','>',$startDate)->where('startDate','>',$endDate)
            ->orWhere('endDate','<',$startDate)->where('startDate','<',$endDate);
        }])->get();
        dd($availableVenue);

Please sign in or create an account to participate in this conversation.