I've been thinking about a similar command few months ago, because I had a specific situation in my project, like You. I decided to make a new command with two parameters:
- refreshPath - for refresh command
- seedClass - for seed command
So, at the first you should make new command:
php artisan make:command NewCommand
In that file, you should have $signature and $description strings, and handle function. You have to include specified parameters (with their default values) to $signature string (because you would use some different tables and seeders in the future).After that, you should call artisan commands with these parameters from handle function. The file should look like this:
class NewCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:new
{refreshPath=/database/migrations/2022_12_20_081911_create_sustainability_pages_table.php}
{seedClass=SustainabilityPageSeeder}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description...';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->call('migrate:refresh --path=' .
$this->argument('refreshPath'));
$this->call('db:seed --class=' .
$this->argument('seedClass'));
return 0;
}
}
At the end, you should call new command from terminal like this:
// if you want default path and class:
php artisan command:new
// if you want some other path and class:
php artisan command:new otherPath otherClass
Hope this helps! :)