Laravel Class env does not exist
在執行artisan
以及相關composer
命令時報錯的
composer dump-autoload
//以及
php artisan config:clear
// 都報下面的錯誤
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
PHP Fatal error: Uncaught ReflectionException: Class env does not exist in /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Container/Container.php:877
Stack trace:
#0 /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(877): ReflectionClass->__construct('env')
#1 /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(758): Illuminate\Container\Container->build('env')
#2 /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve('env', Array, true)
#3 /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\Foundation\Application->resolve('env', Array)
#4 /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make('env', Array)
#5 /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Conta in /www/wwwroot/laravel.vuexy.com/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 879
搜尋一番後找到兩個解決辦法
- LARAVEL CLASS ENV DOES NOT EXIST
- Target class [env] does not exist.
- ReflectionException: Class env does not exist
經過測試驗證未果,然後移除vendor
目錄重新composer update
還是報錯
直接進檔案debug
/www/wwwroot/laravel8/vendor/laravel/framework/src/Illuminate/Conta in /www/wwwroot/laravel8/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 879
//改成
...
try {
$reflector = new ReflectionClass($concrete);
} catch (ReflectionException $e) {
debug_print_backtrace(2);exit;
throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
}
然後執行composer dump-autoload
,報錯
string(31) "Undefined class constant 'HOME'"
string(79) "D:\Workspace\Project\Business\laravel8\config\fortify.php"
string(79) "D:\Workspace\Project\Business\laravel8\config\fortify.php"
PHP Fatal error: Uncaught ReflectionException: Class env does not exist in D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php:877
Stack trace:
#0 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php(877): ReflectionClass->__construct('env')
#1 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php(758): Illuminate\Container\Container->build('env')
#2 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(841): Illuminate\Container\Container->resolve('env', Array, true)
#3 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php(694): Illuminate\Foundation\Application->resolve('env', Array)
#4 D:\Workspace\Project\Business\laravel8\vendor\laravel\framewor in D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 880
Fatal error: Uncaught ReflectionException: Class env does not exist in D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php:877
Stack trace:
#0 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php(877): ReflectionClass->__construct('env')
#1 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php(758): Illuminate\Container\Container->build('env')
#2 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(841): Illuminate\Container\Container->resolve('env', Array, true)
#3 D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php(694): Illuminate\Foundation\Application->resolve('env', Array)
#4 D:\Workspace\Project\Business\laravel8\vendor\laravel\framewor in D:\Workspace\Project\Business\laravel8\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 880
定位到兩個錯誤
Undefined class constant 'HOME'
// fortify.php檔案Fatal error: Uncaught ReflectionException: Class env does not exist
找到資料
To fix the error you can either add the following to your App\Providers\RouteServiceProvider.php
class:
/**
* The path to the "home" route for your application.
*
* @var string
*/
public const HOME = '/home';
更新後搞定
一部分報錯路徑是從虛擬機器目錄擷取的,所以有windows目錄和linux目錄
本作品採用《CC 協議》,轉載必須註明作者和本文連結