I have a use case where we need to modify application flow if the application is being run from the command line via Artisan (migrations, seeds, route:list).
In Laravel 4 this could be done like this:
App::runningInConsole()
Is there an equivalent in Laravel 5?
Using the Environment (.env) variables isn't preferred in this case as these commands occasionally need to be run on production (pointing to production resources) and I'd prefer to avoid resorting to duplicate (.env.commandline) files.
Open the command line terminal on your system. Navigate to your Laravel application directory. Then execute the following PHP artisan command to check the Laravel version. The above output shows that you are running Laravel Framework 7.17.
Artisan is the command line interface frequently used in Laravel and it includes a set of helpful commands for developing a web application.
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.
Not sure about any prior versions but in Laravel 5.2 you can still do App::runningInConsole()
although it's not mentioned in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With