RecursiveMigrationCommand.php 1.2 KB
Newer Older
Thibaud Dauce's avatar
Thibaud Dauce committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php declare(strict_types = 1);

namespace ThibaudDauce\LaravelRecursiveMigrations;

use Symfony\Component\Console\Input\InputOption;

/**
 * @see \Illuminate\Database\Console\Migrations\BaseCommand
 */
trait RecursiveMigrationCommand
{
    use Subdirectories;

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return array_merge(parent::getOptions(), [
            ['recursive', 'r', InputOption::VALUE_NONE, 'Indicates if the migration folders should be flattened.']
        ]);
    }

    /**
     * Get all of the migration paths.
     *
     * @return array
     */
    protected function getMigrationPaths()
    {
        $paths = parent::getMigrationPaths();
        return $this->option('recursive') ? $this->allSubdirectories($paths) : $paths;
    }

    /**
     * Call another console command.
     *
     * @param  string  $command
     * @param  array   $arguments
     * @return int
     */
    public function call($command, array $arguments = [])
    {
        if (starts_with($command, 'migrate')) {
            $arguments['--recursive'] = $this->option('recursive');
        }

        parent::call($command, $arguments);
    }
}