Hi all. I have a problem.
I have a table "saunas" in a database that contains two columns: "station" and "busstation". Each of these columns can have values: empty, null or string.
Each sauna belongs to a certain city. As a result, there are 96 saunas in a particular city.
I want to write an Eloquent query in which I want to select rows in which there are non-empty fields "station" and/or "busstation".
If I just do a "where" query on the "station" field, it works fine. It outputs 54 saunas.
If I do an additional query orWhere in the field "busstation", it outputs all the saunas that are in the database. And there are more than 5000 of them.
What is my mistake?
My relation in the model City.php:
/**
* @return HasMany
*/
public function saunas(): HasMany
{
return $this->hasMany(Sauna::class);
}
My controller SaunasController.php
public function show(City $city)
{
$stations = $city->saunas()
->where(function($query) {
$query->where('station', '<>', '')->whereNotNull('station');
})
->orWhere(function($query) {
$query->where('busstation', '<>', '')->whereNotNull('busstation');
})
->get(['city_id', 'title', 'station', 'busstation']);
}