问题
I use Spatie Laravel package I can take backup by running this command
php artisan backup:run
but I want to take back up form admin panel and running this command form controller, I create a route and controller and in the controller, I do this
public function backup(){
\Artisan::call('backup:run');
return "successfully!";
}
when I route to this finally I got the success message but in the backup file, nothing added.
回答1:
You can put artisan command in sheduler. It will make back up for example every day at the same time. You do it in app/console/Kernel.php
$schedule->command('backup:run')->daily();
Remember to set your server for cron jobs:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Read more: https://laravel.com/docs/5.6/scheduling
来源:https://stackoverflow.com/questions/49789532/running-artisan-command-from-controller-or-route