I gave the paths above to install files. And to make it working for L5 you must inform app/Console/Kernel.php :
protected $commands = [
...
'App\Console\Commands\SeedCommand',
];
I looked for L4, there are many changes and it's not so easy, so I made it :
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class SeedCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:seed';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new Seeder class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Seeder';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/seed.stub';
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$name = $this->argument('name');
if (File::exists($path = $this->getPath($name)))
{
return $this->error($this->type.' already exists!');
}
$this->buildClass($name);
$this->info($this->type.' created successfully.');
}
/**
* Write the seed file to disk.
*
* @param string $name
* @param string $stub
* @return string
*/
protected function writeSeed($name, $stub)
{
$path = $this->getPath($name);
File::put($path, $stub);
}
/**
* Render the fields
*
* @param array $columns
* @param string $stub
* @return void
*/
protected function render($columns, &$stub)
{
$fields = '';
foreach ($columns as $index => $column) {
$fields .= ($index != 0 ? "\t\t\t\t" : '') . "'$column' => " . '$faker->' . ($index != count($columns) - 1 ? ",\r\n" : '');
}
$stub = str_replace('{{fields}}', $fields, $stub);
}
/**
* Build the seed with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$stub = File::get($this->getStub());
$this->replaceFields($stub)->replaceClass($stub, $name)->writeSeed($name, $stub);
}
/**
* Get the destination path.
*
* @param string $name
* @return string
*/
protected function getPath($name)
{
return $this->laravel['path'].'/database/seeds/' . $name . '.php';
}
/**
* Fill the fields for the given stub.
*
* @param string $stub
* @return $this
*/
protected function replaceFields(&$stub)
{
// Get the table name
$table = $this->option('table');
// Test if table exists
if (Schema::hasTable($table))
{
// Get the table columns
$columns = Schema::getColumnListing($table);
// Render
$this->render($columns, $stub);
}
return $this;
}
/**
* Fill the class for the given stub.
*
* @param string $stub
* @return $this
*/
protected function replaceClass(&$stub, $name)
{
$stub = str_replace('{{class}}', $name, $stub);
return $this;
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'Name of the seeder class'],
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['table', null, InputOption::VALUE_REQUIRED, 'The table name.', null]
];
}
}
For L4 and that in app/start/artisan.php :
Artisan::add(new SeedCommand);