filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.66k stars 3k forks source link

Cannot make multiple resource filtered by getEloquentQuery with same model #5071

Closed ayranxs closed 2 years ago

ayranxs commented 2 years ago

Package

filament/filament

Package Version

22.16.52

Laravel Version

9.3.10

Livewire Version

No response

PHP Version

8.1

Problem description

When you create two resources with different labels for same model, it treats as one resource.

For example; when you have Orders model and instead of just showing Orders menu then letting user to use filters to get Pending/Completed orders, you may want to leverage getEloquentQuery on resources to automatically filter out by order state. So this way, you can have Pending Orders / Completed Orders menu.

In Nova, you can create multiple resource for same model, then you can give each other different label and voila; they're added to navigation

Expected behavior

For example, when you have Order model and you created PendingOrdersResource with custom $label (Pending Orders) & CompletedOrdersResource with custom $label (Completed Orders), they should be listed on the navigation as two seperate resources. Instead you'll see two Orders menu on the navigation, when you click on each other, you'll see that the URI is same on them (/admin/orders)

Steps to reproduce

Create a Order model, Create PendingOrders and CompletedOrders resource, Give each resource a different label

Reproduction repository

https://github.com/ayranxs/filament

Relevant log output

No response

github-actions[bot] commented 2 years ago

Hey @ayranxs! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.

github-actions[bot] commented 2 years ago

Thank you for providing reproduction steps! Reopening the issue now.

danharrin commented 2 years ago

Just set the $slug to be different on each resource, as this is generated from the model name. Check the Getting Started docs in the Resources section.

In v3, the slug is generated from the resource name, not the model name, so this isn't an issue.