samedi 29 décembre 2018

How to convert this raw query to eloquent?

I want to convert this raw query that I have do in order to select the available rooms.

    $checkInDate = date("d-m-Y", strtotime($request->start_date));
    $checkOutDate = date("d-m-Y", strtotime($request->end_date));

    $availableRooms = $this->_availablerooms->from('availableRoom as r')
        ->selectRaw('*,r.roomDoorNum, r.isAvailable, rt.title as roomType,res.roomReservedID')
        ->join('roomtype as rt','rt.roomTypeID','=','r.roomTypeID')
        ->leftjoin('roomReserved as rr','rr.roomID','=','r.roomID')
        ->leftjoin('reservation as res','res.roomReservedID','=', DB::raw('rr.roomReservedID AND (res.reservationDate BETWEEN '."$checkInDate".' AND ' ."$checkOutDate". ' OR res.expiryDate BETWEEN '."$checkInDate".' AND ' ."$checkOutDate".')' ))
        ->get();

    return $availableRooms;

I'm new to eloquent so I'm having a hard time doing this.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2EYR7mi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire