我在命令行中输入的任何工匠命令都会抛出此错误:
$ php artisan
<?
return array(
'DB_HOSTNAME' => 'localhost',
'DB_USERNAME' => 'root',
'DB_NAME' => 'pc_booking',
'DB_PASSWORD' => 'secret',
);
PHP Warning: Invalid argument supplied for foreach() in /home/martin/code/www/pc_backend/vendor/laravel/framework/src/Illuminate/Config/EnvironmentVariables.php on line 35
{"error":{"type":"ErrorException","message":"Undefined index: DB_HOSTNAME","file":"\/home\/martin\/code\/www\/pc_backend\/app\/config\/database.php","line":57}}
这只在我的本地开发系统上,我最近安装了apache和php。在我的生产系统上,共享主机上的工匠命令工作正常。 prod系统有自己的.env.php,但除此之外代码应该相同。
相关文件:
.env.local.php
<?
return array(
'DB_HOSTNAME' => 'localhost',
'DB_USERNAME' => 'root',
'DB_NAME' => 'pc_booking',
'DB_PASSWORD' => 'secret',
);
应用程序/配置/ database.php中
<?php
return array(
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOSTNAME'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
'migrations' => 'migrations',
),
);
$ _ENV数组在网站上按预期填充 - 问题似乎只与工匠有关。
答案 0 :(得分:2)
所以我终于找到了解决方法。 事实证明,该文件未被处理为php文件,因为我在.env.local.php文件中使用了一个简短的开头标记。使用正常的开口标签解决了它。我不知道为什么,因为短标签在其他地方工作得很好。