<?php namespace Way\Generators\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class PivotGeneratorCommand extends BaseGeneratorCommand {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'generate:pivot';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate a pivot table';

    public function fire()
    {
        $tables = $this->sortDesiredTables();

        $this->call(
            'generate:migration',
            array(
                'name'      => "pivot_{$tables[0]}_{$tables[1]}_table",
                '--fields'  => "{$tables[0]}_id:integer:unsigned, {$tables[1]}_id:integer:unsigned"
            )
        );
    }

    public function sortDesiredTables()
    {
        $tableOne = str_singular($this->argument('tableOne'));
        $tableTwo = str_singular($this->argument('tableTwo'));

        $tables = array($tableOne, $tableTwo);
        sort($tables);

        return $tables;
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array(
            array('tableOne', InputArgument::REQUIRED, 'Name of the first table.'),
            array('tableTwo', InputArgument::REQUIRED, 'Name of the second table.')
        );
    }

}


<?php namespace Way\Generators\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class PivotGeneratorCommand extends BaseGeneratorCommand {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'generate:pivot';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generate a pivot table';

    public function fire()
    {
        $tables = $this->sortDesiredTables();

        $this->call(
            'generate:migration',
            array(
                'name'      => "pivot_{$tables[0]}_{$tables[1]}_table",
                '--fields'  => implode(', ', array(
                    "{$tables[0]}_id:integer:unsigned:index",
                    "{$tables[1]}_id:integer:unsigned:index",
                    "{$tables[0]}_id:foreign:references('id'):on('{$tables[0]}'):onDelete('cascade')",
                    "{$tables[1]}_id:foreign:references('id'):on('{$tables[1]}'):onDelete('cascade')"
                ))
            )
        );
    }

    public function sortDesiredTables()
    {
        $tableOne = str_singular($this->argument('tableOne'));
        $tableTwo = str_singular($this->argument('tableTwo'));

        $tables = array($tableOne, $tableTwo);
        sort($tables);

        return $tables;
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return array(
            array('tableOne', InputArgument::REQUIRED, 'Name of the first table.'),
            array('tableTwo', InputArgument::REQUIRED, 'Name of the second table.')
        );
    }

}


Make pivot table generation more robust
Make pivot table generation more robust
