从控制器或路线运行artisan命令 [英] Running artisan command from controller or route
问题描述
我使用Spatie Laravel软件包,我可以通过运行以下命令进行备份
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.
推荐答案
您可以将artisan命令放在sheduler中.例如,它将在每天的同一时间进行备份.您可以在 app/console/Kernel.php
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();
记住要为cron作业设置服务器:
Remember to set your server for cron jobs:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
了解更多: https://laravel.com/docs/5.6/scheduling
这篇关于从控制器或路线运行artisan命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!