0

Как узнать приложение на Laravel было запущено из консоли или через броузер?

1 ответ 1

1
  • Проверить запущено ли приложение из консоли можно app()->runningInConsole().

  • Запущено тестом: app()->runningUnitTests()

Реализация в Laravel 8:

public function runningInConsole()
{
  if ($this->isRunningInConsole === null) {
    $this->isRunningInConsole = Env::get('APP_RUNNING_IN_CONSOLE') ?? (\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg');
  }

  return $this->runningUnitTests;
}

/**
 * Determine if the application is running unit tests.
 *
 * @return bool
 */
public function runningUnitTests()
{
  return $this['env'] === 'testing';
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.