2016_03_03_113126_create_posts_table.php 864 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use Illuminate\Database\Schema\Blueprint;
  3. use Illuminate\Database\Migrations\Migration;
  4. class CreatePostsTable extends Migration
  5. {
  6. /**
  7. * Run the migrations.
  8. *
  9. * @return void
  10. */
  11. public function up()
  12. {
  13. Schema::create('posts', function(Blueprint $table) {
  14. $table->increments('id');
  15. $table->timestamps();
  16. $table->string('titre', 80);
  17. $table->text('contenu');
  18. $table->integer('user_id')->unsigned();
  19. $table->foreign('user_id')
  20. ->references('id')
  21. ->on('users')
  22. ->onDelete('restrict')
  23. ->onUpdate('restrict');
  24. });
  25. }
  26. /**
  27. * Reverse the migrations.
  28. *
  29. * @return void
  30. */
  31. public function down()
  32. {
  33. Schema::table('posts', function(Blueprint $table) {
  34. $table->dropForeign('posts_user_id_foreign');
  35. });
  36. Schema::drop('posts');
  37. }
  38. }