在尝试使用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
在Google上搜索此问题后,我尝试了以下解决方案但其中没有一个有效:
vendor
文件夹和composer.lock
,然后运行composer install
bootstrap/compiled.php
,然后运行composer update
php artisan cache:clear
或php artisan views:clear
以清空storage/views
目录。 php artisan
也不起作用storage/views
,但也失败了我将文件夹的权限更改为777
,以防它是权限问题,但也失败了。
这里是composer.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"
}
更新
所以我一直跟踪storage/views
从第foreach
个循环中找到的错误:
<div class="sub-menu">
@foreach($_destinationsList as $destination)
<ul>
<li>
<a href="{{_url('destination/'.$destination->slug)}}">{{$destination->{_en('name')._ar('name_ar')} }}</a>
</li>
@foreach($destination->children as $destination)
<li>
<a href="{{_url('destination/'.$destination->slug)}}">{{$destination->{_en('name')._ar('name_ar')} }}</a>
</li>
@endforeach
</ul>
@endforeach
</div>
除此之外,我发现url
函数前面有_
,据我记得Laravel 4.2不存在,你只需要写url('url here')
。此外,en
和ar
也会遇到同样的问题。第一个foreach
循环保持陈述Invalid argument supplied for foreach
,这很奇怪,因为我无法使用php artisan
迁移数据库甚至将其播种。
更奇怪的是,相同的代码目前正在运行且正常工作。
知道这里有什么问题吗?!
答案 0 :(得分:0)
你试过sudo作曲家安装/更新吗?我今天遇到了类似的问题并用sudo修复了
答案 1 :(得分:0)
虽然这很奇怪,但我发现了错误。数据库配置中的host
设置为localhost
,由于某些未知原因,它无法正常工作并提供上述错误。我将其更改为127.0.0.1
并且它正常工作。
我无法弄清楚真正的原因,因为错误跟踪中没有与此部分相关的内容。