Create
Tools
Account
Free & open source
On GitHub
Resources
Community
Platform
Open Source
Kareem Elsharkawy
May 30th, 2020
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
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();