-
I am using the Rappasoft Laravel Livewire Tables package to display a table of employees in my Laravel application. The table is supposed to display each employee along with their latest compensation details. Although the query works as expected in terms of fetching data, I am encountering an issue where each employee is displayed multiple times if they have more than one compensation record. EmployeeTable Component (shortened):
Employee Model
Problem: When an employee has multiple compensation records, the EmployeeTable displays one row for each compensation record instead of displaying only the latest compensation. This results in duplicate employee rows in the table view. What I've Tried: Ensured that the latestCompensation relationship uses ->latest('startdate') to fetch the latest record. Environment: Laravel version: 10.48 Expected Behavior: Each employee should appear only once in the table, showing the most recent compensation information. Additional Information: If anyone has experience with handling similar issues using Rappasoft Livewire Tables or has insights on how to effectively limit the result set to include only the latest related record, your assistance would be greatly appreciated. Thank you for your help! Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Yep, I've not yet got to the bottom of the best way to handle this, so there's no official fix as of yet! The latest() is not something I actually use day-to-day, so any suggestions are appreciated. |
Beta Was this translation helpful? Give feedback.
-
So, if you are working with HasMany, because, if an Employee can have more that one compensation is a HasMany relationship, the table will show duplicated records for that, now, in my own app i don't handle employees but i have products with prices, it's almost the same structure, in your case you need to filter that relationship with another options. I solve my problem a few weeks ago, my solution was to focus in the From this: to this:
Now my price Column looks like this:
Of course, for other parts of my app I need to use the Maybe is not the best, but is the first solution that works for me. |
Beta Was this translation helpful? Give feedback.
-
This approach should work for the interim. This assumes that "User" Things having: And the "latestThing" is the most recent created_by "Things"
And in your builder:
|
Beta Was this translation helpful? Give feedback.
How could I have overlooked the fact that the sortabel method also allows a callback. Thank you very much for this hint.
My column now looks like this and works as expected: