Getting Undefined index: REQUEST_URI - When Run Artisan Commands in Laravel

最后都变了- 提交于 2019-12-30 10:57:11

问题


I keep getting the error below every time I try to run an artisan command on Laravel, I'm on the project directory.

For example, I run this command:

php artisan make:migration create_stats_table

And I get this error:

  [ErrorException]              
  Undefined index: REQUEST_URI

No matter what command I run, I get the same error, even php artisan --version returns this error. How can I solve this problem?


回答1:


Your code expects to have this index, but you're running PHP in CLI mode. REQUEST_URI variable of $_SERVER superglobal is only available if you're reaching script by browser.




回答2:


As mentioned already this variable doesn't exist if you run by the CLI. If you can't get around the issue and avoid using it a work around is to use isset()

if (isset($_SERVER['REQUEST_URI'])){ 
...
}


来源:https://stackoverflow.com/questions/42352663/getting-undefined-index-request-uri-when-run-artisan-commands-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!