Aronaman
3 months ago

query on the search

Posted 3 months ago by Aronaman

the organization has a child -room (one to many relationships with an organization) and on the organization, there is city_id field

search rooms with the city do not get any value

SearchRoomController

public function index(){

    $cities=City::all();
        $roomType=Roomtype::all();
        $rooms=Room::with('organization')
        ->when(request('room_type'), function($query){
            return $query->where('roomtype_id', request('room_type'));
        })
        ->when(request('city_id'),function($query){
                return $query->where('organization.city_id',request('city_id'));
            })

on the search blade

<div class="col-sm-6 col-md-4 col-lg-3 mb-4">
            <div class="select-wrap">
              <span class="icon icon-arrow_drop_down"></span>
              <select name="room_type" id="room_type" class="form-control d-block rounded-0">
                <option value="">--Room Type--</option>
              @foreach($typeOfRoom as $roomType)
                <option value="{{$roomType->id}}">{{$roomType->name}}</option>
               @endforeach
              </select>
            </div>
          </div>
         

          <div class="col-sm-6 col-md-4 col-lg-3 mb-4">
            <div class="select-wrap">
              <span class="icon icon-arrow_drop_down"></span>
              <select name="city_id" id="city_id" class="form-control d-block rounded-0">
                <option value="">--city--</option>
                @foreach($cities as $city)
                <option value="{{$city->id}}">{{$city->name}}</option>
                @endforeach
              </select>
            </div>
          </div>

organization.php

 public function rooms()
    {
        return $this->hasMany(Room::class);
    }

room.php

 public function organization()
    {
        return $this->belongsTo(Organization::class, 'organization_id');
    }

the error is where('organization.city_id', ....no column in the DB

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