本篇文章給大家?guī)?lái)了關(guān)于Laravel的相關(guān)知識(shí),其中主要給大家介紹在Laravel9中提示了Target *classController does not exist,該怎么辦?下面一起來(lái)看一下解決方案,希望對(duì)需要的朋友有所幫助。
關(guān)于 laravel 9 提示 Target *classController does not exist
關(guān)于 laravel 9 api 提示 Target class [App\\Http\\Controllers\\CaptchasController] does not exist 解決方法
1、打開 app\Providers\RouteServiceProvider.php 修改如圖
class RouteServiceProvider extends ServiceProvider { . . . . . protected $namespace ='App\\Http\\Controllers'; public function boot() { $this->configureRateLimiting(); $this->routes(function () { Route::middleware('api') ->prefix('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); }); } }
2、打開 app\Providers\RouteServiceProvider.php 修改如圖
<?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; //use App\Http\Controllers\Api\CaptchasController; Route::prefix('v1') ->name('api.v1.') ->namespace("Api")//添加命名空間 ->group(function () { Route::middleware('throttle:'. config('api.rate_limits.sign')) ->group(function () { // Route::post('captchas', [CaptchasController::class, 'store'])->name('captchas.store'); ---原來(lái)的 Route::post('captchas', 'CaptchasController@store') ->name('captchas.store');// 修改成這樣即可 }); Route::middleware('throttle:' .config('api.rate_limits.access')) ->group(function () { }); })