php 类 App\Http\Controllers\ 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45162881/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:05:15  来源:igfitidea点击:

Class App\Http\Controllers\ does not exist

phplaravelcontrollerroutes

提问by Joseph Carlo

This is my Route:

这是我的路线:

 Route::get('/hello', '@HomeController@index');

This is my HomeController

这是我的 HomeController

namespace App\Http\Controllers;
use app\Requests;
use Illuminate\Http\Requests;
use Spatie\Activitylog\Models\Activity;
use Illuminate\Database\Eloquent\Model;  
use Illuminate\Support\Facades\Auth;

class HomeController extends Controller {

   public function index() {
    $lastActivity = Spatie\Activitylog\Models\Activity::all();
    return view('activity'), compact('lastActivity'));
   }

}

But I keep on getting an error message:

但我不断收到错误消息:

 ReflectionException in Route.php line 280:
 Class App\Http\Controllers\ does not exist

What can I do? Thanks.

我能做什么?谢谢。

回答by Joel Hinz

You have an extra @ in your method call.

您的方法调用中有一个额外的 @。

'@HomeController@index'

should be

应该

'HomeController@index'

回答by Gulmuhammad Akbari

At the first of controller you do not need to put @, its just for method of controller.

在控制器的第一个你不需要放置@,它只是控制器的方法。

 Route::get('/hello', 'HomeController@index');

回答by Cherma Ramalho

Whenever errors of type ReflectionException occur, you should check the routes in the routes/api.php and routes/web.php files to correct them.

每当出现 ReflectionException 类型的错误时,您应该检查 routes/api.php 和 routes/web.php 文件中的路由以更正它们。