gpt4 book ai didi

拉拉维尔 : Class controller does not exist

转载 作者:行者123 更新时间:2023-12-02 12:21:52 26 4
gpt4 key购买 nike

我创建了一个简单的 Controller 并定义了一个函数。但是当我运行它时,它返回一个错误,指出 Controller 不存在。

在我的 web.php 中指定一个路由。

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

在我的 Controller 的另一边我的代码:

<?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');
}
}

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

错误:

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

最佳答案

Front部分添加到:

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

此外,将 Controller 的顶部更改为:

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

并运行composer du

来自the docs :

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.

关于拉拉维尔 : Class controller does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48617556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com