【发布时间】:2021-10-24 18:26:27
【问题描述】:
我知道这个问题已经被问过好几次了,但没有一个答案对我有用,所以我再次问这个问题。
我正在尝试在 Laravel 中创建一个小网站,并创建了一个路由和一个控制器,但是当我尝试在 url 中访问它时,我收到了这个错误:
Illuminate\Contracts\Container\BindingResolutionException
Target class [Admin\PlanController] does not exist.
这是我的web.php:
use Illuminate\Support\Facades\Route;
Route::get('admin/plans', 'Admin\PlanController@index')->name('plans.index');
Route::get('/', function () {
return view('welcome');
});
这是我的PlanController.php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PlanController extends Controller
{
public function index(){
return view('admin.pages.plans.index');
}
}
如果有任何帮助,这里是我的RouteServiceProvider.php
protected $namespace = 'App\\Http\\Controllers';
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
【问题讨论】:
-
您缺少我认为的默认命名空间。你可以添加你的路线吗? Laravel 8?
-
确保您使用正确的
nameplans.index访问您的anchor标签