Getting Undefined index: REQUEST_URI - When Run Ar

2020-03-30 05:06发布

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?

2条回答
甜甜的少女心
2楼-- · 2020-03-30 05:33

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'])){ 
...
}
查看更多
迷人小祖宗
3楼-- · 2020-03-30 05:36

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.

查看更多
登录 后发表回答