Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if running from the command line in Laravel 5

Tags:

php

laravel-5

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.

like image 545
Forrest Marvez Avatar asked Mar 18 '15 19:03

Forrest Marvez


People also ask

How do I know if Laravel is running?

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.

What is console in Laravel?

Artisan is the command line interface frequently used in Laravel and it includes a set of helpful commands for developing a web application.

Which one of the given CLI is used for Laravel?

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.


1 Answers

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.

like image 182
Fahmi Avatar answered Oct 02 '22 21:10

Fahmi