Laravel 4.2 - 作曲家更新问题

Laravel 4.2 - composer update issue

在使用 Laravel 项目之前,我尝试像往常一样 运行 作曲家安装和作曲家更新。但是我遇到了一个奇怪的问题,我似乎很长一段时间都无法解决。

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                                             

用谷歌搜索这个问题后,我尝试了以下解决方案,但 none 个解决方案有效:

  1. 正在删除 vendor 文件夹和 composer.lock,然后 运行正在 composer install
  2. 删除 bootstrap/compiled.php 然后 运行 宁 composer update
  3. 运行宁php artisan cache:clearphp artisan views:clear清空storage/views目录。 php artisan也不行
  4. 我尝试手动删除 storage/views,但也失败了
  5. 作曲家更新 --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')enar 也遵循同样的问题。第一个 foreach 循环一直显示 Invalid argument supplied for foreach,这很奇怪,因为我不能使用 php artisan 来迁移数据库,甚至不能为它做种子。

更奇怪的是,相同的代码目前正在正常运行。

知道这里的问题是什么吗?!

你试过sudo composer install/update吗?我今天遇到了类似的问题并用 sudo

修复了它

虽然这很奇怪,但我发现了错误。数据库配置中的 host 设置为 localhost 并且由于某些未知原因它无法正常工作并出现上述错误。我把它改成了127.0.0.1,它正常工作。

我无法找出真正的原因,因为在错误跟踪中没有与这部分相关的内容。