2023_04_23_233249_create_views_table.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. use Illuminate\Support\Facades\Schema;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class CreateViewsTable extends Migration
  6. {
  7. /**
  8. * The database schema.
  9. *
  10. * @var \Illuminate\Support\Facades\Schema
  11. */
  12. protected $schema;
  13. /**
  14. * The table name.
  15. *
  16. * @var string
  17. */
  18. protected $table;
  19. /**
  20. * Create a new migration instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. $this->schema = Schema::connection(
  27. config('eloquent-viewable.models.view.connection')
  28. );
  29. $this->table = config('eloquent-viewable.models.view.table_name');
  30. }
  31. /**
  32. * Run the migrations.
  33. *
  34. * @return void
  35. */
  36. public function up()
  37. {
  38. $this->schema->create($this->table, function (Blueprint $table) {
  39. $table->bigIncrements('id');
  40. $table->morphs('viewable');
  41. $table->text('visitor')->nullable();
  42. $table->string('collection')->nullable();
  43. $table->timestamp('viewed_at')->useCurrent();
  44. });
  45. }
  46. /**
  47. * Reverse the migrations.
  48. *
  49. * @return void
  50. */
  51. public function down()
  52. {
  53. Schema::dropIfExists($this->table);
  54. }
  55. }