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.

API 117<br />

19 $table->text('description');<br />

20 $table->timestamps();<br />

21 });<br />

22 }<br />

23<br />

24 /**<br />

25 * Reverse the migrations.<br />

26 *<br />

27 * @return void<br />

28 */<br />

29 public function down()<br />

30 {<br />

31 Schema::drop('sponsor');<br />

32 }<br />

33 }<br />

.<br />

This file should be saved as app/database/migrations/00000000_000000_create_sponsor_table.php.<br />

The last couple of migrations we need to create are for pivot tables to connect sponsors and categories<br />

to events. Pivot tables are common in HABTM (Has And Belongs To Many) relationships, between<br />

database entities.<br />

The command for these is just as easy:<br />

1 php artisan generate:pivot event category<br />

2<br />

3 php artisan generate:pivot event sponsor<br />

4 These commands generate the following migrations:<br />

1

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

Saved successfully!

Ooh no, something went wrong!