I really like the Laravel framework for having a documentation excellent that has always met my needs. For your case, there is a paragraph (Programmatically Executing Commands) which explains how you can use Facade Artisan
.
An example to run db:seed
anywhere your project is as follows:
public function initialize()
{
// Rollback em todas as migrações e migrar as tabelas novamente
Artisan::call('migrate:refresh');
// Alimentar as tabelas
Artisan::call('db:seed', ['--class' => 'TabelaSeeder']);
}
Or you can pass the entire command as a string:
Artisan::call('db:seed --class=TabelaSeeder');