当前位置: 首页 > news >正文

larvel 中的api.php_Laravel 开发 API

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

    <?phpuse Illuminate\Support\Facades\Route;Route::get('/', [App\Http\Controllers\IndexController::class, 'index'])->name('admin.index.index');?>

再次访问URL,搞定。

解决方法二:

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

<?phpnamespace App\Providers;use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;class RouteServiceProvider extends ServiceProvider
{/*** The path to the "home" route for your application.** Typically, users are redirected here after authentication.** @var string*/public const HOME = '/home';/************此处添加*START**********************/    protected $namespace = 'App\Http\\Controllers\\Api';/************此处添加*END**********************//*** Define your route model bindings, pattern filters, and other route configuration.** @return void*/public function boot(){$this->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());});}
}

http://www.lryc.cn/news/208910.html

相关文章:

  • 虚拟机构建部署单体项目及前后端分离项目
  • C++之特殊类的设计
  • Java练习题2020 -1
  • LuaTable转C#的列表List和字典Dictionary
  • Redis快速上手篇七(集群)
  • Mac 安装nvm
  • python 从mssql取出datetime2类型之后格式化
  • 18.2 使用NPCAP库抓取数据包
  • pytest-yaml 测试平台-3.创建执行任务定时执行用例
  • 安卓文件资源中,一个字串包含引用其他字串的写法
  • 解决:谷歌浏览器访问http时,自动转https访问的问题
  • MQTT协议和边缘计算
  • Redis(04)| 数据结构-压缩列表
  • 516 最长回文子序列(区间DP)(灵神笔记)
  • Kafka - 异步/同步发送API
  • 嵌套for循环在外层循环和内层循环中使用两个Executors.newCachedThreadPool缓存线程池执行操作
  • 【uniapp+云函数调用】人脸识别,实人认证,适用于app,具体思路解析,已实现
  • 系列十六、bean有哪些生命周期的回调方法?有哪几种实现方式?
  • 2023平台工程崭露头角,AI 带来新机遇与挑战
  • 如何使用python快速修改Excel表单中的大量数据
  • ✔ ★【备战实习(面经+项目+算法)】 10.27学习
  • 视频分辨率/帧率/码率选择参考
  • LeetCode75——Day18
  • Java NIO 高并发开发
  • 8.循环神经网络
  • [C++随想录] map和set的使用
  • 公网IP怎么设置?公网ip有哪些优点和缺点?
  • 蓝桥杯第 2 场算法双周赛 第2题 铺地板【算法赛】c++ 数学思维
  • APScheduler-调度器 BackgroundScheduler
  • 浅谈UI自动化测试