• larvel 中的api.php_Laravel 开发 API


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

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

    再次访问URL,搞定。

    解决方法二:

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

    1. <?php
    2. namespace App\Providers;
    3. use Illuminate\Cache\RateLimiting\Limit;
    4. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
    5. use Illuminate\Http\Request;
    6. use Illuminate\Support\Facades\RateLimiter;
    7. use Illuminate\Support\Facades\Route;
    8. class RouteServiceProvider extends ServiceProvider
    9. {
    10. /**
    11. * The path to the "home" route for your application.
    12. *
    13. * Typically, users are redirected here after authentication.
    14. *
    15. * @var string
    16. */
    17. public const HOME = '/home';
    18. /************此处添加*START**********************/
    19. protected $namespace = 'App\Http\\Controllers\\Api';
    20. /************此处添加*END**********************/
    21. /**
    22. * Define your route model bindings, pattern filters, and other route configuration.
    23. *
    24. * @return void
    25. */
    26. public function boot()
    27. {
    28. $this->configureRateLimiting();
    29. $this->routes(function () {
    30. Route::middleware('api')
    31. ->prefix('api')
    32. /************此处添加*START**********************/
    33. ->namespace($this->namespace)
    34. /************此处添加*END**********************/
    35. ->group(base_path('routes/api.php'));
    36. Route::middleware('web')
    37. ->group(base_path('routes/web.php'));
    38. });
    39. }
    40. /**
    41. * Configure the rate limiters for the application.
    42. *
    43. * @return void
    44. */
    45. protected function configureRateLimiting()
    46. {
    47. RateLimiter::for('api', function (Request $request) {
    48. return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
    49. });
    50. }
    51. }

  • 相关阅读:
    spring boot项目如何采用war在tomcat容器中运行呢?
    什么是三合一网站建设,网站内容多语言是建站的趋势
    java创建线程的3种方式
    Git 分支管理策略汇总
    汇编基础知识
    【做题小技巧】乘法得出的数超过int怎么办
    Java/Android设计模式学习笔记
    MySQL中常用的数据类型
    gRpc入门
    变量、流程控制与游标(MySQL)
  • 原文地址:https://blog.csdn.net/weixin_39616995/article/details/134081916