Running artisan command from controller or route

4.5k Views Asked by At

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

There are 1 best solutions below

0
On

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