Running artisan command from controller or route

帅比萌擦擦* 提交于 2020-12-31 05:59:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!