Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

francis_sebin_fernandez's avatar

Resource Hasmany:: submodel filtering

Hi

Thanks in advance,

I'm new to Laravel Nova

I have 2 models App\Models\Product and App\Models\User. User hasMany Product and Product belongsTo User. My products table got a column called status.

I need to show products with active status in the user resource of nova. Added HasMany::make('Products') in User resource and it showing all products created by that user both active and inactive. But I need only to show products with status active.

0 likes
2 replies
philipbaginski's avatar

Hi! Make filter - look into docs how to make it, or add to resource:

 public static function indexQuery(NovaRequest $request, $query)
 {
     return $query->where('status', 1); (In my case 1 = active)
 }
francis_sebin_fernandez's avatar

Hi, This is working, but it will also affect the parent resource table, I mean that the product resource index. I want to list all kinds of products here regardless of status. What I'm looking for is to list products with transfer status inside the individual users who create them.

Please or to participate in this conversation.