laravel9框架报错Target class... does not exist解决方式
在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'); ---原来的
Route::post('captchas', '[email protected]')
->name('captchas.store');// 修改成这样即可
});
Route::middleware('throttle:' .config('api.rate_limits.access'))
->group(function () {
});
})
相关文章