3
I need to create a method that compares in two or more arrays if the current date is greater than the due dates (date_paymentX) that exist in these arrays and returns how many occurrences there are.
Method:
public function payments()
{
$date = date('Y-m-d'); // Retorna 2017-08-09
$services = Service::all()->toArray();
dd($services);
}
dd() displays:
array:2 [▼
0 => array:22 [▼
"id" => 1
"date" => "2017-08-09"
"date_payment1" => "2017-08-01"
"price1" => "500"
"payment1" => "Não"
"date_payment2" => "2017-08-15"
"price2" => "500"
"payment2" => "Não"
"date_payment3" => "2017-08-20"
"price3" => "500"
"payment3" => "Não"
"customer_id" => 1
"created_at" => "2017-08-09 10:52:12"
"updated_at" => "2017-08-09 12:28:31"
]
1 => array:22 [▼
"id" => 2
"date" => "2017-08-09"
"date_payment1" => "2017-08-01"
"price1" => "500"
"payment1" => "Não"
"date_payment2" => "2017-08-15"
"price2" => "500"
"payment2" => "Não"
"date_payment3" => "2017-08-15"
"price3" => "500"
"payment3" => "Não"
"customer_id" => 1
"created_at" => "2017-08-09 12:09:56"
"updated_at" => "2017-08-09 12:29:12"
]
]
In this example there are 2 past due payments. You would need the method to return this value(2).
I liked your answer. Better than mine to tell you the truth. You can answer your own question. And in my opinion yours is more performatic.
– Andrei Coelho