Include latest hasMany record in table
I have a Members model with hasMany Payments relatinship. I want to show the latest payment date as a column in the Members table. Is that possible?
6 Replies
I think it is. You would need to define a new relationship on your Members model, something like
latestPayment
and then you would chain the filtering info on it
something like:
The
limit(1)
part is a problem. I get only 1 latestPayment per page ...Isnt that what you want? Just the latest payment? In your members table, use
TextColum::make('member.latestPayment.date')
(or whatever your models and columns are named)
if you have a separate payments table, just use the ecisting payments() relation without a limit
I used this in my project
latestOfMany()
instead of latest()
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.