You can use where and other sql based methods for relationship objects.
This means that you can create your own method in your model:
class Restaurant extends Eloquent { protected $table = 'restaurants'; public function facilities($wifi) { return $this->belongsTo('Facility')->where('wifi', '=', $wifi); } }
Or you can try using query areas :
class Restaurant extends Eloquent { protected $table = 'restaurants'; public function facility() { return $this->belongsTo('Restaurant'); } public function scopeFiltered($query, $wifi) { return $query->where('wifi', '>', 100); } }
Then:
$wifi = 1; $restaurants = Restaurant::facilities()->filtered($wifi)->get();
This is not exactly what you need, but you probably want to use the query areas to get what you are trying.
The main thing to know is that relationship classes can be used as query builders - for example:
$this->belongsTo('Facility')->where('wifi', '=', $wifi)->orderBy('whatever', 'asc')->get();
source share