larvel 中的api.php_Laravel 开发 API

Laravel10中提示了Target *classController does not exist,为什么呢?
原因是:laravel8开始写法变了。换成了新的写法了
解决方法一:
在路由数组加入App\Http\Controllers\即可。

    name('admin.index.index');
     
    ?>

再次访问URL,搞定。

解决方法二:

打开 app\Providers\RouteServiceProvider.php 修改,添加一个namespace变量

configureRateLimiting();

        $this->routes(function () {
            Route::middleware('api')
                ->prefix('api')
                /************此处添加*START**********************/  
                ->namespace($this->namespace)
                 /************此处添加*END**********************/
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->group(base_path('routes/web.php'));
        });
    }

    /**
     * Configure the rate limiters for the application.
     *
     * @return void
     */
    protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
        });
    }
}

你可能感兴趣的:(laravel,php)