03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

E-Commerce 231<br />

10 Schema::create("product", function($table)<br />

11 {<br />

12 $table->engine = "InnoDB";<br />

13<br />

14 $table->increments("id");<br />

15 $table->string("name");<br />

16 $table->integer("stock");<br />

17 $table->float("price");<br />

18 $table->dateTime("created_at");<br />

19 $table->dateTime("updated_at");<br />

20 $table->dateTime("deleted_at");<br />

21 });<br />

22 }<br />

23<br />

24 public function down()<br />

25 {<br />

26 Schema::dropIfExists("product");<br />

27 }<br />

28 }<br />

.<br />

This file should be saved as app/database/migrations/nnnn_nn_nn_nnnnnn_CreateProduct-<br />

Table.php.<br />

There’s nothing particularly special about these - we’ve create many of them before. What is<br />

important to note is that we’re calling the traditional user table account.<br />

.<br />

You can learn more about migrations at: http://laravel.com/docs/schema.<br />

The relationships might not yet be apparent, but we’ll see them more clearly in the models…<br />

Creating Models<br />

We need to create the same amount of models. I’ve gone ahead and created them with table names<br />

matching those defined int he migrations. I’ve also added the relationship methods:

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

Saved successfully!

Ooh no, something went wrong!