I created a Laravel console command in routes/console.php
. I would like to run this command from a migration? How can I do it?
I would like to avoid using the PHP's exec()
function because it's unpredictable where the path of my laravel app is going to be and which OS will be run on.
I am using Laravel 5.x
Roll Back & Migrate Using A Single CommandThe migrate:refresh command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database: php artisan migrate:refresh. # Refresh the database and run all database seeds... php artisan migrate:refresh -- ...
IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh . IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrate again. Also, you can try php artisan migrate --seed if you have any seeder.
You can use
Artisan::call('email:send');
From docs with command parameters
$exitCode = Artisan::call('email:send', [
'user' => 1, '--queue' => 'default'
]);
https://laravel.com/docs/5.6/artisan#programmatically-executing-commands
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With