laravel 前端有?id=12这么一个api请求,请教路由怎么写
前端请求:http://***.test/api/v1/list?id=17
Route::get('/api/v1/list?id={id}', [\App\Http\Controllers\SignController::class, 'list']);
提示这样的错误
Oops! An Error Occurred
The server returned a "405 Method Not Allowed".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
本作品采用《CC 协议》,转载必须注明作者和本文链接
关于 LearnKu
ilst 后面删掉 用方法中加参数 ,
function test(Request $reques).用$request->get('id');当然还有其他方法我懒得打字明白了,谢谢
405就是你的请求方式错了,接口定义的是
get请求方式看看是不是也是get如果不一样就会报405。可以用路由参数传递 ID,依赖注入
方法
路由参数的定义及获取参数方式有
两种方式一:
方式二:
还有一个需要注意的地方
方法名不要使用关键词, 例如:list先把文档看一遍吧,或者找个入门教程
推荐一个》laravelacademy.org/books/laravel-t...