Conditionnal relationship

Submitted by Matt - 10 years ago

It's possible to add condition to your model's relationships... Help me to use Eloquent with a legacy database..

class myModel extents Model
{
    ...
    
    public function category() {
    	return $this->belongsTo('myCategoryModel', 'categories_id')->where('users_id', Auth::user()->id);
	}
    
    ...
}