Laravel Class env does not exist 问题排查
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
找到资料
Undefined class constant ‘App\Providers\RouteServiceProvider::HOME’
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 协议》,转载必须注明作者和本文链接
一般遇到
PHP Fatal error: Uncaught ReflectionException:
这种错误,是框架在启动时报错。可以使用这个方法打印异常来定位到具体的错误 —— Wiki:Laravel Eloquent:获取模型查询生成的 SQL 语句
@Summer 嗯,是启动时报的错,我瞅瞅,谢谢~