Question By
Unsolved

Add Scope To Belongs To Many Relation

kareem-elsharkawy-1

May 30th, 2020 06:14 PM

I need to Add Scope to Belongs To Many Relation i have used

				public function scopeParents($query)
		{
				return $query->whereNull('parent_id');
		}

but it's not working

cookie

Jun 7th, 2020 08:54 PM

Why is this not working? You have to append it to your Relation like:

public function relationship()
{
   return $this->hasMany('MyClass')->parents();
}

Or inline, in your code by doing something like that:

$var = Model::all()->parents();
Report
1