lundi 10 juillet 2017

Laravel 5.1 return eloquent between time_start and time_end

Here's my Sample Table:

reservation_date | time_start | time_end 7/10/2017 | 12:00:00 | 14:00:00

what i'm trying to do is to return all reservations between time_start and time_end base on the request by the user. and sub/add 2 hours from time_start and time_end to prevent conflicts. I tried

$times_data = $this->getTimesData($request->reservation_time_start, $request->reservation_time_end);

$reservations =  $reservations->whereBetween('reservation_time_start', $times_data)

protected function getTimesData($time_start, $time_end)
    {

        $time_from = $this->getTimeFrom($time_start);

        $time_to = $this->getTimeTo($time_end);

        return [$time_from, $time_to];
    }

protected function getTimeFrom($time)
    {
        $time = Carbon::parse($time);

        return $time->subHours(2)->toTimeString();
    }


    protected function getTimeTo($time)
    {
        $time = Carbon::parse($time);

        return $time->addHours(2)->toTimeString();
    }

But the result is not what i expected. i also tried

->whereRaw("(reservation_time_start BETWEEN ? AND ?) AND (reservation_time_end BETWEEN ? AND ?) ",$times_data)

but it returns null. Please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire