每当我尝试从命令行运行任何php artisan
命令时,我都会收到以下错误:
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","me
ssage":"Call to a member function connection() on a non-object","file":"C:\\wamp
\\www\\cms\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Mod
el.php","line":2649}}{"error":{"type":"Symfony\\Component\\Debug\\Exception\\Fat
alErrorException","message":"Call to a member function connection() on a non-obj
ect","file":"C:\\wamp\\www\\cms\\vendor\\laravel\\framework\\src\\Illuminate\\Da
tabase\\Eloquent\\Model.php","line":2649}}
我已经在我的composer.json中将Laravel版本指定为4.1。*但由于我无法运行工匠,我不知道确切的版本。
此问题以前没有发生过。尽管php artisan
中出现了错误,但该网站似乎运行良好。就我所知,Composer命令也可以正常工作。
为什么会发生这种情况?
答案 0 :(得分:0)
此错误似乎已经发生,因为对于app/config/mail.php
中的邮件配置,我使其从数据库中检索值,而不是直接在该文件中指定配置选项。
因此,我必须检查是否从Web或命令行调用了获取值的函数。如果从命令行调用该函数,我只返回一个空字符串。
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
return '';
}