Question: I have 2 models: `city` and `hotel`. And they have 1 to n relationship. I want my user to be able to search in both models at once.

So when I want my api to be called when ever my user type any word which is the frontends concern, but I get to problem when it comes to searching.

I want to search in 2 models to see any similarity and return the data, for example if user types the word 

```
N

```

I want to return the 2 object 1 in hotel and 1 in city:

```
New York

```

and 

```
Hotel navara 

```

Here are my defined relations in models:

```
 public function city()
    {
        return $this->hasOne(City::class, 'id', 'city_id');
    }

```

And in my city model :

```
 public function hotel(){
        return $this->hasMany(Hotel::class);
    }

```

Answer: 
You can use `orWhere` like this 

```
$result = City::orWhereHas('hotel', function (Builder $query) use($request) {
    $query->where('name', 'like', '%' . $request->name . '%');
})->orWhere('name', 'like', '%' . $request->name . '%')->get();

```

hope this helps.

Thanks
Try this and let me know what is happening
Hotel.php

```
public function city()
   {
        return $this->belongsTo(City::class, 'id', 'city_id');
    }

```

City.php

```
public function hotel()
    {
        return $this->hasMany(City::class, 'id', 'city_id');
    }

```

In Controller 

```
$city= City::find(1);

$hotels = $city->hotel;

dd($hotels);

```

If it is not work let me see the dd().. I jope it helps