Created
October 18, 2019 22:57
-
-
Save vfsoraki/28f4c85073d294ee7a1986931714e849 to your computer and use it in GitHub Desktop.
Run arbitrary scripts in context of a Laravel application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This Artisan command can run any file in the context of application. | |
* It can be useful to test some scripts in production/staging to see what's happening. | |
* You can also use `$this->*` functions in script. | |
* This reads scripts from `storage` folder, but nothing prevents you from changing it. | |
**/ | |
Artisan::command('run:script {script}', function ($script) { | |
$full_path = storage_path($script); | |
if (file_exists($full_path)) { | |
require $full_path; | |
} else { | |
$this->error("File {$script} does not exist in `storage` folder, double check name."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment