Reputation:
I want to select rows based on one column which is customer_id. Now the situation is there is a column ccustomer_id in Invoices table.
Here is how I am getting it now
Invoice::where('payment_status',1)->get()
But problem with this query is if there are two invoices for customer it will get both invoice. I need only latest one?
What will be query for that thing?
Upvotes: 0
Views: 196
Reputation: 136
here is what you need to do
Invoice::where('payment_status',1)->order_by('created_at', 'desc')->first();
Upvotes: 2