0

I'm doing exactly what is described here

However, I added this code in my resource

public static function indexQuery(NovaRequest $request, $query)
{
   
   return $query->doesntHave('parent');
}

In order to only show in index, Posts that did not contain parent;

Problem is that this query is also applied in HasMany field;

Children didn't shown on Post Detail

I'm wondering if there's something like $request->isFromRelation() that return true if $request is made for relation purpose and then, I can do this :

public static function indexQuery(NovaRequest $request, $query)
{
   if(!$request->isFromRelation())
        return $query->doesntHave('parent');
}
Goms
  • 2,424
  • 4
  • 19
  • 36

1 Answers1

0

I finally found solution for this problem !

There's method $request->viaRelatonship() that did the exactly thing I expected ! There's unfortunately no mention of that in documentation!

Anyway, I have now the missing part of my code :

public static function indexQuery(NovaRequest $request, $query)
{
   if(!$request->viaRelationship())
        return $query->doesntHave('parent');
}
Goms
  • 2,424
  • 4
  • 19
  • 36