Check if input is from console

You can check if you are running in the console by using

app()->runningInConsole()

Underneath that, all it does is check the interface type

return php_sapi_name() == 'cli' || php_sapi_name() == 'phpdbg'

You can find more on the PHP Docs site


To detect whether the app is running in console, you can do something like this:

use Illuminate\Support\Facades\App;

if(App::runningInConsole())
{
  // app is running in console
}

See, illuminate/Foundation/Application.php:520