php 找不到类“App\Http\Controllers\Controller” - Laravel 5.2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35117781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'App\Http\Controllers\Controller' not found - Laravel 5.2
提问by Ciapss
I am new here but I already checked all solutions about my problem here and still didn't fix it.
我是新来的,但我已经在这里检查了有关我的问题的所有解决方案,但仍然没有解决。
I want to create simple app with tutorial in Laravel 5.2, and I can't make my controller to work.
我想在 Laravel 5.2 中使用教程创建简单的应用程序,但我无法让我的控制器工作。
I named my app "test" and here is a code:
我将我的应用程序命名为“test”,这是一个代码:
PagesController.php:
页面控制器.php:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class PagesController extends Controller
{
public function getAbout(){
return view('about');
}
}
routes.php:
路线.php:
Route::get('about', [
'as' => 'about',
'uses' => 'PagesController@getAbout'
]);
And Controller.php (default):
和 Controller.php(默认):
<?php
namespace test\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
Do you see any problem here? I am sure all files are in correct folders.
你看这里有什么问题吗?我确定所有文件都在正确的文件夹中。
回答by Captain Sparrow
Error can also occur if App/Http/Controllers/folder does not have Controller.phpfile.
如果App/Http/Controllers/文件夹没有Controller.php文件,也会发生错误。
Make sure file exists.
确保文件存在。
回答by PlayMa256
To make everything correct, run this.
为了使一切正确,运行这个。
php artisan app:name YourApplicationName
it is going to change everything with app to your application name, so you wont need to write manually test everywhere
它会将 app 中的所有内容更改为您的应用程序名称,因此您无需到处手动编写测试
回答by Drudge Rajen
Please correct your namespace in your pagecontroller
请更正页面控制器中的命名空间
<?php
namespace test\Http\Controllers;
use test\Http\Controllers\Controller;
class PagesController extends Controller
{
public function getAbout(){
return view('about');
}
}
UPDATE :
更新 :
After change in namespace in controller please dump-autoload your composer:
更改控制器中的命名空间后,请转储自动加载您的作曲家:
Composer dump-autoload
Composer 转储自动加载
回答by Ciapss
My controller now looks like this:
我的控制器现在看起来像这样:
<?php
namespace test\Http\Controllers;
use test\Http\Controllers\Controller;
class PagesController extends Controller
{
public function getAbout(){
return view('about');
}
}
And error is still there
错误仍然存在
Update:
更新:
Okay, I created a new project and it finnaly works. I think all ansewrs will be helpful for similiar problems :)
好的,我创建了一个新项目,它最终有效。我认为所有的答案都会对类似的问题有所帮助:)
Thanks for help !
感谢帮助 !