-1

I couldn't find something that do it in one line but...

After a search I found that works perfectly with me but if any have better solution please write it below

first refresh it

php artisan migrate:refresh --path=/database/migrations/2022_12_20_081911_create_sustainability_pages_table.php

then: seed it

php artisan db:seed --class=SustainabilityPageSeeder
Tomatoes
  • 39
  • 8
  • Questions on Stack Overflow should ask questions. Solutions likewise belong in answers, not in the question. – TylerH Mar 17 '23 at 20:02

1 Answers1

1

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! :)