Favorite products: many to many not working
I have an app where users can favor many products. This is done via a many to many relation with a Favorite pivot table. Adding things into the database works.
The
favorites
table is as follows:
In Filament I have a Favorites resources where the idea is the user can get an overview of the products he's favoured. In a Filament table I have the following:
The username is printed but the product name is not. Any idea how to do this? I keep on struggling with this.
Some more information in case relevant:
User Model:
Product model:
Favorite model:
3 Replies
You should install Laravel Debugbar and see what SQL queries are executed under the hood, and see if the correct products are queried at all. Could they be soft-deleted or something?
Thanks Povilas. I did follow your suggestion and found indeed something interesting. The query that gets executed is
I have a multi-tenancy setup and by default Filament is configured to only show the products that are part of the organization tenant.
When I change the products (manually in the database) to belong to the logged in organization, the data will show correctly. When the products belong to other organizations, the information does not show.
I have a middleware as follows:
Not sure if there is a way to apply the global scope to all resources, except Favorites? Or perhaps there's better suggestions?
Tried with in the FavoriteResource but does not work
Sorry I don't have a quick answer without experimenting and debugging