Home > PHP Framework > Laravel > Quickly solve the problem of laravel9 prompting 'Target *classController does not exist'!

Quickly solve the problem of laravel9 prompting 'Target *classController does not exist'!

藏色散人
Release: 2023-01-28 19:51:24
forward
2761 people have browsed it

本篇文章给大家带来了关于Laravel的相关知识,其中主要给大家介绍在Laravel9中提示了Target *classController does not exist,该怎么办?下面一起来看一下解决方案,希望对需要的朋友有所帮助。

Quickly solve the problem of laravel9 prompting 'Target *classController does not exist'!

关于 laravel 9 提示 Target *classController 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'));
        });
    }
}
Copy after login

2. 打开 app\Providers\RouteServiceProvider.php 修改如图

<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\Api\CaptchasController;
Route::prefix(&#39;v1&#39;)
    ->name(&#39;api.v1.&#39;)
    ->namespace("Api")//添加命名空间
    ->group(function () {
         Route::middleware(&#39;throttle:&#39;.
         config(&#39;api.rate_limits.sign&#39;))
        ->group(function () {
           // Route::post(&#39;captchas&#39;, [CaptchasController::class, &#39;store&#39;])->name(&#39;captchas.store&#39;); ---原来的
              Route::post(&#39;captchas&#39;, &#39;CaptchasController@store&#39;)
              ->name(&#39;captchas.store&#39;);// 修改成这样即可
     });
           Route::middleware(&#39;throttle:&#39; .config(&#39;api.rate_limits.access&#39;))
            ->group(function () {
            });
    })
Copy after login

推荐学习:《laravel视频教程

The above is the detailed content of Quickly solve the problem of laravel9 prompting 'Target *classController does not exist'!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template