当我更改命名空间时,为什么我的应用程序崩溃?

时间:2015-04-12 05:54:57

标签: laravel composer-php laravel-5

我按照 Easy Laravel 5 一书中提供的材料学习Laravel。所以我按照指示创建了应用,当我访问localhost:8000时,我看到了欢迎页面。

然后我给了名字改变命令:

php artisan app:name todoparrot

系统以Application namespace set!回复。但是现在当我重新加载localhost:8000时,我什么都没看到,服务该应用程序的终端给了我一长串错误:

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class todoparrot\Console\Kernel does not exist' in /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Container/Container.php:776
Stack trace:
#0 /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Container/Container.php(776): ReflectionClass->__construct('todoparrot\Cons...')
#1 /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('todoparrot\Cons...', Array)
#2 /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(613): Illuminate\Container\Container->make('todoparrot\Cons...', Array)
#3 /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Container/Container.php(229): Illuminate\Foundation\Application->make('todoparrot\Cons...', Array)
#4 /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Container/Container.php(773): Illuminate\Container\Con in /media/common/htdocs/todoparrot/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 776

现在我甚至无法运行artisan,因为我一直遇到同样的错误。知道因为这个极其简单的变化可能会被打破吗?

3 个答案:

答案 0 :(得分:15)

重命名后尝试此命令:

composer dump-autoload

Composer在vendor/composer/目录中的自动加载文件中包含您的命名空间。当你改变任何你需要清除它并再次生成它时,该命令就可以了。

答案 1 :(得分:1)

如果您运行以下命令,它将更改所有命名空间和路径到todoparrot。在你的情况下,没有找到Laravel"类todoparrot \ Console \ Kernel不存在"。确保命名空间已更改为todoparrot

php artisan app:name todoparrot

该命令将修改以下所有文件

modified:   app/Commands/Command.php
modified:   app/Console/Commands/Inspire.php
modified:   app/Console/Kernel.php
modified:   app/Events/Event.php
modified:   app/Exceptions/Handler.php
modified:   app/Http/Controllers/Auth/AuthController.php
modified:   app/Http/Controllers/Auth/PasswordController.php
modified:   app/Http/Controllers/Controller.php
modified:   app/Http/Controllers/HomeController.php
modified:   app/Http/Controllers/WelcomeController.php
modified:   app/Http/Kernel.php
modified:   app/Http/Middleware/Authenticate.php
modified:   app/Http/Middleware/RedirectIfAuthenticated.php
modified:   app/Http/Middleware/VerifyCsrfToken.php
modified:   app/Http/Requests/Request.php
modified:   app/Http/routes.php
modified:   app/Providers/AppServiceProvider.php
modified:   app/Providers/BusServiceProvider.php
modified:   app/Providers/ConfigServiceProvider.php
modified:   app/Providers/EventServiceProvider.php
modified:   app/Providers/RouteServiceProvider.php
modified:   app/Services/Registrar.php
modified:   bootstrap/app.php
modified:   composer.json
modified:   config/app.php
modified:   config/auth.php

app / Console / Kernel.php中的示例命令将更改此

namespace App\Console;

protected $commands = [
    'App\Console\Commands\Inspire',
];

namespace todoparrot\Console;

protected $commands = [
    'todoparrot\Console\Commands\Inspire',
];

如果" App \"请检查文件app / Console / Kernel.php。路径仍然可用。如果可以,请转到" todoparrot \"。

我已经尝试运行命令" php artisan app:name todoparrot"。它没有任何问题。我不知道为什么它会给你的错误。

答案 2 :(得分:-1)

Ggo到C:\ wamp \ www \ laravel \在命令提示符下使用

C:\ProgramData\ComposerSetup\bin\composer dump-autoload

而不是

composer dump-autoload