Detect if running from the command line in Laravel 5

后端 未结 4 456
感情败类
感情败类 2021-02-03 22:16

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条回答
  •  北海茫月
    2021-02-03 23:15

    Anyone can use laravel app() helper function to avoid any namespace related issue. So to check if script is running in cli or browser, can be using this line of code app()->runningInConsole()

    Basic usage:

    if ( app()->runningInConsole() ){
        // it's console.
    }
    

提交回复
热议问题