@@ -9,7 +9,14 @@ class RoomRepository implements RoomRepositoryInterface
9
9
{
10
10
public function getRooms ($ request )
11
11
{
12
- $ rooms = Room::with ('type ' , 'roomStatus ' )->orderBy ('number ' );
12
+ $ rooms = Room::with ('type ' , 'roomStatus ' )
13
+ ->orderBy ('number ' )
14
+ ->when ($ request ->status , function ($ query ) use ($ request ) {
15
+ $ query ->where ('room_status_id ' , $ request ->status );
16
+ })
17
+ ->when ($ request ->type , function ($ query ) use ($ request ) {
18
+ $ query ->where ('type_id ' , $ request ->type );
19
+ });
13
20
if (!empty ($ request ->search )) {
14
21
$ rooms = $ rooms ->where ('number ' , 'LIKE ' , '% ' . $ request ->search . '% ' );
15
22
}
@@ -43,6 +50,12 @@ public function getRoomsDatatable($request)
43
50
'rooms.price ' ,
44
51
'room_statuses.name as status ' ,
45
52
)
53
+ ->when ($ request ->status !== 'All ' , function ($ query ) use ($ request ) {
54
+ $ query ->where ('room_status_id ' , $ request ->status );
55
+ })
56
+ ->when ($ request ->type !== 'All ' , function ($ query ) use ($ request ) {
57
+ $ query ->where ('type_id ' , $ request ->type );
58
+ })
46
59
->leftJoin ("types " , "rooms.type_id " , "= " , "types.id " )
47
60
->leftJoin ("room_statuses " , "rooms.room_status_id " , "= " , "room_statuses.id " );
48
61
0 commit comments