Laravel:类控制器不存在 [英] Laravel : Class controller does not exist

查看:399
本文介绍了Laravel:类控制器不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的控制器并定义了一个功能.但是当我运行它时,它返回一个错误,提示控制器不存在.

I have created a simple controller and define a function. But when i run this it returns an error that controller does not exist.

在我的web.php中分配一条路由.

In my web.php assign a route.

<?php
  Route::get('/', function () { return view('front.welcome'); });
  Route::get('plan','PlanController@PlanActivity')->name('plan');

在我控制器的另一侧,我的代码:

On otherside in my controller my code:

<?php
 namespace App\Http\Controllers\Front;
 use App\Http\Controllers\Controller as BaseController;
 use Illuminate\Http\Request;

class PlanController extends Controller {

public function PlanActivity()
{
    dd("hello");
    //return view('admin.index');
}
}

在App \ Http \ Controllers \ Front-前文件夹上创建的此控制器

This controller created on App\Http\Controllers\Front - on front folder

错误:

ReflectionException(-1) 类App \ Http \ Controllers \ PlanController不存在

ReflectionException (-1) Class App\Http\Controllers\PlanController does not exist

推荐答案

Front部分添加到:

Route::get('plan', 'Front\PlanController@PlanActivity')->name('plan');

此外,将控制器的顶部更改为:

Also, change the top of the controller to:

namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

然后运行composer du.

来自文档:

默认情况下,RouteServiceProvider将路由文件包含在名称空间组中,从而使您无需指定完整的App\Http\Controllers命名空间前缀即可注册控制器路由.因此,您只需要指定名称空间中位于基本App\Http\Controllers名称空间之后的部分即可.

By default, the RouteServiceProvider includes your route files within a namespace group, allowing you to register controller routes without specifying the full App\Http\Controllers namespace prefix. So, you only need to specify the portion of the namespace that comes after the base App\Http\Controllers namespace.

这篇关于Laravel:类控制器不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆