0
votes

I want to create restore.php file for laravel script. I added restore file on public folder. and when I want to use artisan command on this file, show me this error.

( ! ) Fatal error: Uncaught RuntimeException: A facade root has not been set. in C:\wamp64\www\myscript\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 218 ( ! ) RuntimeException: A facade root has not been set. in C:\wamp64\www\myscript\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 218

restore.php:

<?php
 use Illuminate\Support\Facades\Artisan;


include '../vendor/autoload.php';

Artisan::call('migrate');

Note: I do not want to use Laravel controller for restore database because maybe script was down.

1

1 Answers

1
votes

You cannot do it like this. Laravel is a bit more complicated so including autoloader is not enough. You should take a look what is in public/index.php file but if you want to create script you run from console probably the best option is to create Artisan command than just trying to manually run the flow to make it work.

And if you just want to run existing command (or command you created) you can create route like this:

Route::get('/down', function() {
     Artisan::call('down', ['--message' => 'Restore Mode']);
});

and then in browser you can just run http://yoururl.com/down - of course make sure you will allow to run such urls only for some types of users and not all