PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

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