Laravel 4.2 - 作曲家更新问题
Posted
技术标签:
【中文标题】Laravel 4.2 - 作曲家更新问题【英文标题】:Laravel 4.2 - composer update issue 【发布时间】:2016-08-06 06:18:16 【问题描述】:在使用 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
在谷歌上搜索了这个问题后,我尝试了以下解决方案,但都没有奏效:
-
删除
vendor
文件夹和composer.lock
,然后运行composer install
删除bootstrap/compiled.php
,然后运行composer update
运行php artisan cache:clear
或php artisan views:clear
以清空storage/views
目录。 php artisan
也不行
我尝试手动删除storage/views
,但也失败了
作曲家更新 --no-scripts。
我将文件夹的权限更改为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
来迁移数据库甚至播种它。
更奇怪的是,相同的代码目前正在正常运行。
知道这里可能是什么问题吗?!
【问题讨论】:
您是否尝试手动删除 app/storage/views 中的所有内容? 如果您在 IDE 中打开一个项目,您是否碰巧看到项目文件夹堆栈中带有下划线之类的错误? @Norgul 我正在使用括号编辑器,所以没有下划线错误 下次运行时,打开引用的文件并追踪错误。它不喜欢您的代码中的某些内容。解决这个问题,希望它可以工作。 @aynber 你能说得更具体点吗?!该错误似乎在我通常不会更改的 storage/views 文件夹中,所以我可以修复它吗?! 【参考方案1】:您是否尝试过 sudo 作曲家安装/更新?我今天遇到了类似的问题并用 sudo 修复了它
【讨论】:
我总是使用 sudo 运行命令,所以直到现在它都不起作用【参考方案2】:虽然这很奇怪,但我发现了错误。数据库配置中的host
设置为localhost
,由于某种未知原因,它无法正常工作并出现上述错误。我把它改成127.0.0.1
,它工作正常。
我无法弄清楚真正的原因,因为错误跟踪中没有与这部分相关的内容。
【讨论】:
以上是关于Laravel 4.2 - 作曲家更新问题的主要内容,如果未能解决你的问题,请参考以下文章
作曲家错误 - 您的要求无法解决 - Laravel 4.2 on Mediatemple