我想与以下人员分享我的观点变量:
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Schema::defaultStringLength(191);
$customers = Customer::get();
\View::share('customers', $customers);
}
}
它按预期工作,但是当我想通过 artisan 迁移我的表时,它会抛出一个错误,即
customers
的表未找到,因为在迁移开始之前对其进行了检查。所以我需要类似的东西if(!artisan_request) {
//request to laravel is via web and not artisan
}
但是我在文档中没有找到任何东西。
最佳答案
您可以使用以下方法检查您是否在控制台中运行
app()->runningInConsole()
在此之下,它所做的只是检查接口(interface)类型
return php_sapi_name() == 'cli' || php_sapi_name() == 'phpdbg'
您可以在 PHP Docs site 上找到更多信息
关于laravel - 检查输入是否来自控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44112238/