mardi 17 janvier 2017

How to chain method with Model current state?

I have a model where I get total of order like this:

public function total()
{
    $total = $this->subtotal();
    foreach ($this->lineItems as $l) {
        $total += $l->amount;
    }
    return $total;
}

I want to add method formated() which will format subtotal and total method returns with function number_format($numberHere, 2).

I want it to be dynamic not like: totalFormated or subtotalFormated. I want to output formated value like this: $order->total()->formated();.

Is there any chance I can get that to work?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iElzUj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire