sergionc
6 months ago
319
2
Laravel

idea to calculate with conditional

Posted 6 months ago by sergionc

Can you give me the idea, I have two fields in my table.

field_1 (always has a value of 5)

field_2 (depends on the days of delay is multiplied by the value of field_1)

My idea would be to use carbon to get the current date and subtract it from the date it was created and in that way multiply by the value of field_1.

But how to do it in a controller since they are for all rows that have a value of 5 in field_1

public function show($id)
{
    $pago = Pago::with('junta','socio')->findOrFail($id);
    $fecha = Carbon::now();
    $freg = $pago->created_at->diffInDays();
    $cpago = $pago->multa;
    $cmulta = $freg*$cpago;
    return view('pago.show', compact('pago','fecha','cmulta'));
}

so get by id, but if I want for all rows and it is done automatically.

Please sign in or create an account to participate in this conversation.