laravel闲聊一下的Route::middleware(‘auth:api‘)里面的auth:api的意思

Route::middleware(‘auth:api’)->get(’/user’, function (Request $request) {
return $request->user();
});
安装好了laravel框架以后,在路由文件api.php里面有上面一行代码,这行代码就是定义路由
但是突然对auth:api这个具体是怎么回事好奇,就查询了一下

其中auth是中间件的名字,这个名字对应的是在kernel.php文件里面
在这里插入图片描述
这个倒不难解释,主要是后面的api是啥意思,是不是因为模块是api模块才这么写的,还是因为在api.php里面就要写api。其实都不是,具体代码看下面
在这里插入图片描述
上面截图的路径是
vendor\laravel\framework\src\Illuminate\Auth\Middleware\Authenticate.php

我打印了一下$guards就是传过来的api这个参数。然后下面的代码就是去读取
config/auth.php文件里面的guards配置
在这里插入图片描述
好了,原理到这里就结束了

还有不懂的可以通过微信小程序的客服联系我,有问必答
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是因为你的代码中使用了 FastAPI 版本低于 0.60.0,而 `fastapi.middleware.multipart` 模块是在 0.60.0 版本中添加的。你可以升级 FastAPI 到最新版本,使用以下命令: ``` pip install fastapi --upgrade ``` 如果你需要使用旧版本的 FastAPI,你可以使用 `python-multipart` 模块来处理 `multipart/form-data` 数据格式,而不需要使用 `fastapi.middleware.multipart` 模块。你可以使用以下代码来处理 `multipart/form-data` 数据格式: ```python from fastapi import FastAPI, Form, File, UploadFile from fastapi.param_functions import Depends from fastapi.security import OAuth2PasswordRequestForm from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from fastapi.exceptions import RequestValidationError app = FastAPI() # 添加 CORS 中间件 origins = [ "http://localhost", "http://localhost:8000", "http://localhost:8080", "https://localhost", "https://localhost:8000", "https://localhost:8080", ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # 定义路由和处理函数 @app.post("/uploadfile/") async def create_upload_file(file: bytes = File(...)): return {"file_size": len(file)} @app.post("/form/") async def create_form_file(file: bytes = Form(...)): return {"file_size": len(file)} @app.post("/uploadfiles/") async def create_upload_files(files: list = File(...)): return {"file_sizes": [len(file) for file in files]} @app.post("/login/") async def login(form_data: OAuth2PasswordRequestForm = Depends()): return {"username": form_data.username} ``` 在上面的代码中,我们使用 `File` 和 `Form` 参数来处理 `multipart/form-data` 数据格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值