03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

E-Commerce 281<br />

1 public function getTotalAttribute()<br />

2 {<br />

3 $total = 0;<br />

4<br />

5 foreach ($this->orderItems as $orderItem)<br />

6 {<br />

7 $total += $orderItem->price * $orderItem->quantity;<br />

8 }<br />

9<br />

10 return $total;<br />

11 }<br />

.<br />

This was extracted from app/models/Order.php.<br />

.<br />

These two additional model methods allow us to get the totals of orders and order items quickly. You<br />

can learn more about Eloquent attribute getters at: http://laravel.com/docs/eloquent#accessorsand-mutators.<br />

1 <br />

2 <br />

3 <br />

4 <br />

5 Laravel 4 E-Commerce<br />

6 <br />

7<br />

8 body {<br />

9 padding : 25px 0;<br />

10 font-family : Helvetica;<br />

11 }<br />

12<br />

13 td {<br />

14 padding : 0 10px 0 0;<br />

15 }<br />

16<br />

17 * {<br />

18 float : none;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!