I tried to run composer install and composer update as usual before working with a Laravel project. However I encountered a weird issue that I can't seem to solve for quite a while.
在使用Laravel项目之前,我尝试像往常一样运行composer install和composer update。然而,我遇到了一个奇怪的问题,我似乎很久都无法解决。
PHP Fatal error: Uncaught exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7:35
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7(35): Illuminate\Exception\Handler->handleError(2, 'Invalid argumen...', '/Applications/X...', 35, Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(35): include('/Applications/X...')
#2 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(56): Illuminate\View\Engines\PhpEngine->evaluatePath('/Applications/X...', Array)
#3 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/framework/src/Illuminate/View/View.php(134): Illuminate\View\Engines\CompilerEngine->get('/Applications/X...', Array)
#4 /Applications/XAMPP/xamppfiles/htdocs/ in /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7 on line 35
PHP Fatal error: Uncaught exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7:35
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7(35): Illuminate\Exception\Handler->handleError(2, 'Invalid argumen...', '/Applications/X...', 35, Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(35): include('/Applications/X...')
#2 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(56): Illuminate\View\Engines\PhpEngine->evaluatePath('/Applications/X...', Array)
#3 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/framework/src/Illuminate/View/View.php(134): Illuminate\View\Engines\CompilerEngine->get('/Applications/X...', Array)
#4 /Applications/XAMPP/xamppfiles/htdocs/ in /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7 on line 35
Script php artisan clear-compiled handling the post-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Fatal error: Uncaught exception 'ErrorException' with me
ssage 'Invalid argument supplied for foreach()' in /Applications/XAMPP/xamp
pfiles/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de
3dc7:35
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d
4682a7a7da163c9444d69f6b6de3dc7(35): Illuminate\Exception\Handler->handleEr
ror(2, 'Invalid argumen...', '/Applications/X...', 35, Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/fram
ework/src/Illuminate/View/Engines/PhpEngine.php(35): include('/Applications
/X...')
#2 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/fram
ework/src/Illuminate/View/Engines/CompilerEngine.php(56): Illuminate\View\E
ngines\PhpEngine->evaluatePath('/Applications/X...', Array)
#3 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/fram
ework/src/Illuminate/View/View.php(134): Illuminate\View\Engines\CompilerEn
gine->get('/Applications/X...', Array)
#4 /Applications/XAMPP/xamppfiles/htdocs/ in /Applications/XAMPP/xamppfiles
/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7 o
n line 35
PHP Fatal error: Uncaught exception 'ErrorException' with message 'Invalid
argument supplied for foreach()' in /Applications/XAMPP/xamppfiles/htdocs/
wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7:35
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/app/storage/views/d
4682a7a7da163c9444d69f6b6de3dc7(35): Illuminate\Exception\Handler->handleEr
ror(2, 'Invalid argumen...', '/Applications/X...', 35, Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/fram
ework/src/Illuminate/View/Engines/PhpEngine.php(35): include('/Applications
/X...')
#2 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/fram
ework/src/Illuminate/View/Engines/CompilerEngine.php(56): Illuminate\View\E
ngines\PhpEngine->evaluatePath('/Applications/X...', Array)
#3 /Applications/XAMPP/xamppfiles/htdocs/wild-guanabana/vendor/laravel/fram
ework/src/Illuminate/View/View.php(134): Illuminate\View\Engines\CompilerEn
gine->get('/Applications/X...', Array)
#4 /Applications/XAMPP/xamppfiles/htdocs/ in /Applications/XAMPP/xamppfiles
/htdocs/wild-guanabana/app/storage/views/d4682a7a7da163c9444d69f6b6de3dc7 o
n line 35
After googling this issue, I tried the following solutions but none of them worked:
在谷歌搜索这个问题后,我尝试了以下解决方案,但都没有成功:
vendor
folder and composer.lock
and then running composer install
bootstrap/compiled.php
and then running composer update
php artisan cache:clear
or php artisan views:clear
to empty the storage/views
directory. php artisan
also does not workstorage/views
manually but it also failedI changed the folder's permission to 777
just in case it was a permission issue but it also failed.
我将文件夹的权限更改为777,以防这是一个权限问题,但它也失败了。
Here's composer.json just in case:
这是作曲家。json以防:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.7"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
UPDATE:
更新:
so I kept tracing the error I was getting from storage/views
to find it in the first foreach
loop:
所以我一直跟踪我从存储/视图中得到的错误,在第一个foreach循环中找到它:
@foreach($_destinationsList as $destination)
-
{{$destination->{_en('name')._ar('name_ar')} }}
@foreach($destination->children as $destination)
-
{{$destination->{_en('name')._ar('name_ar')} }}
@endforeach
@endforeach
Adding to that I find the url
function preceded by _
which as far as I remember Laravel 4.2 was not there, you just write url('url here')
. Also the en
and ar
follow the same issue. The first foreach
loop keep stating Invalid argument supplied for foreach
, which is weird since I can't use php artisan
to migrate the database or even seed it.
另外,我发现url函数前面有_,我记得Laravel 4.2没有,你只需写url('url here')。en和ar也遵循同样的问题。第一个foreach循环继续声明为foreach提供的无效参数,这很奇怪,因为我不能使用php artisan来迁移数据库,甚至不能对它进行种子。
What is more weird is that the same code is currently live and working normally.
更奇怪的是,同样的代码现在是正常工作的。
Any idea what could be the issue here?!
你知道这里有什么问题吗?
0
have you tried the sudo composer install/update? I had similar issues today and fixed it with sudo
你试过sudo composer安装/更新吗?我今天遇到了类似的问题,用sudo解决了
0
Although this is weird, but I found the error. The host
in the database configuration was set to localhost
and for some unknown reason it was not working and giving the errors stated above. I changed it to 127.0.0.1
and it worked normally.
虽然这很奇怪,但是我发现了错误。数据库配置中的主机被设置为localhost,出于某种未知原因它不能工作,并给出上面所述的错误。我把它改成了127.0.0.1,它正常工作。
I can not figure out the real reason since there is nothing related to this part in the error trace.
我无法找出真正的原因,因为在错误跟踪中与这部分没有任何关系。