InstallCommand.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Illuminate\Database\Console\Migrations;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Database\Migrations\MigrationRepositoryInterface;
  5. use Symfony\Component\Console\Attribute\AsCommand;
  6. use Symfony\Component\Console\Input\InputOption;
  7. #[AsCommand(name: 'migrate:install')]
  8. class InstallCommand extends Command
  9. {
  10. /**
  11. * The console command name.
  12. *
  13. * @var string
  14. */
  15. protected $name = 'migrate:install';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Create the migration repository';
  22. /**
  23. * The repository instance.
  24. *
  25. * @var \Illuminate\Database\Migrations\MigrationRepositoryInterface
  26. */
  27. protected $repository;
  28. /**
  29. * Create a new migration install command instance.
  30. *
  31. * @param \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository
  32. * @return void
  33. */
  34. public function __construct(MigrationRepositoryInterface $repository)
  35. {
  36. parent::__construct();
  37. $this->repository = $repository;
  38. }
  39. /**
  40. * Execute the console command.
  41. *
  42. * @return void
  43. */
  44. public function handle()
  45. {
  46. $this->repository->setSource($this->input->getOption('database'));
  47. $this->repository->createRepository();
  48. $this->components->info('Migration table created successfully.');
  49. }
  50. /**
  51. * Get the console command options.
  52. *
  53. * @return array
  54. */
  55. protected function getOptions()
  56. {
  57. return [
  58. ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'],
  59. ];
  60. }
  61. }