php - How to define a dynamic attribute for a many to many relationship in Laravel 5? -


i have many-to-many relationship orders products, follows:

class order extends model {     ...     public function products()     {         return $this->belongstomany('app\product')                     ->withpivot('unit_price', 'quantity');     } } 

i can access attributes of relationship using $order->pivot->unit_price , $order->pivot->quantity.

but there way can create accessors relationship?
instance, $order->pivot->subtotal return unit_price * quantity.

yes can, looking pivot class, easy implement, here's tutorial you.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -