2016-04-14 222 views
6

我嘗試在使用Laravel項目之前像往常一樣運行作曲家安裝和作曲家更新。但是,我遇到了一個我似乎無法解決的奇怪問題。Laravel 4.2 - 作曲家更新問題

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            

谷歌搜索這個問題之後,我嘗試以下解決方案,但沒有一次成功:

  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. 作曲家更新 - 無腳本。

我更改文件夾的權限爲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" 
} 

UPDATE:

所以我一直跟蹤我從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來遷移數據庫或甚至爲它創建種子。

更奇怪的是,相同的代碼目前正常工作並正常工作。

任何想法可能是這裏的問題?!

+0

您是否嘗試手動刪除app/storage/views中的所有內容? – aynber

+0

@aynber是的,我做過 – omarsafwany

+0

如果你在你的IDE中打開一個項目,你是否碰巧看到下劃線,就像項目文件夾堆棧中的錯誤一樣? – Norgul

回答

0

雖然這很奇怪,但我發現錯誤。數據庫配置中的host被設置爲localhost,並且由於某些未知原因,它無法正常工作並出現上述錯誤。我將它更改爲127.0.0.1,它正常工作。

我找不出真正的原因,因爲在錯誤追蹤中沒有任何與此部分相關的原因。

0

你試過了sudo composer安裝/更新嗎?我今天有類似的問題,並修復它與sudo

+0

我總是使用sudo運行命令,直到現在它不工作 – omarsafwany