Check If The App Is Running From Console

If you need to check if the app is run from the console and not the browser, like usually, there's a simple function for this.

Laravel has Commands, which allow you to easily run the app from your console through Artisan and there's a way to check this.

How to check if you are running from the console

In order to find app if you are running in the console, you can use App::runningInConsole(), which will return true or false.

Below you can see a very basic example of checking this:

if (App::runningInConsole())
{
    // Do something if you're running in console
}

You should know that runningInConsole() implements PHP's php_sapi_name() function and it returns true if the function returns cli.