create_favorite_tables.php.stub 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of ibrand/favorite.
  4. *
  5. * (c) iBrand <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Illuminate\Support\Facades\Schema;
  11. use Illuminate\Database\Schema\Blueprint;
  12. use Illuminate\Database\Migrations\Migration;
  13. class CreateFavoriteTables extends Migration
  14. {
  15. /**
  16. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  23. if (!Schema::hasTable($prefix . 'favorite')) {
  24. Schema::create($prefix . 'favorite', function (Blueprint $table) {
  25. $table->increments('id');
  26. $table->unsignedInteger('user_id')->comment('用户id');
  27. $table->unsignedInteger('favoriteable_id')->comment('收藏的id');
  28. $table->string('favoriteable_type')->comment('收藏的类型(如:商品 ,故事)');
  29. $table->timestamps();
  30. });
  31. }
  32. }
  33. /**
  34. * Reverse the migrations.
  35. *
  36. * @return void
  37. */
  38. public function down()
  39. {
  40. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  41. Schema::dropIfExists($prefix . 'favorite');
  42. }
  43. }