php - Laravel 不支持获取方法
问题描述
我在从 Laravel 的数据库中获取一些信息时遇到了一些问题。我正在尝试使用 where 方法并指定我需要的 id 但我总是有错误
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The GET method is not supported for this route. Supported methods: POST.
这是代码控制器
public function select_category($category_id){
$products = Products::where('category_id', $category_id)->get();
return $products;
}
api
Route::get('products/{category_id}', 'ProductsController@select_category');
当我删除$category_id
和在哪里,只有喜欢的Products::all();
作品正常,但需要指定在哪里搜索。
链接我如何指定 $category_id 是http://localhost:8000/api/products/?category_id=16
解决方案
更改您的网址:
http://localhost:8000/api/products/16
还要更改视图文件:
<a href="{{ URL::to('products/'. $yourchategoryid ) }}">product</a>
推荐阅读
- linux - 从文字变量输入创建序列
- python - 如何在“pyscipopt”中创建变量向量?
- libreoffice-basic - 如何在 LibreOffice 宏中设置焦点(用于 Base 表单)?或者设置一个不过滤的“Position-To”字段?
- xcode - 使用嵌入式框架构建后 Xcode 找不到标头
- ios - “界面高清”需要更新
- swiftui - SwiftUI 视频播放器
- go - Go:如何不删除 cookie 上的双引号
- python - 'ModuleNotFoundError: No module named 'keras.engine.base_layer_v1'' 运行 PyInstaller .exe 文件时
- debugging - VSCode lua 调试扩展
- nginx - 如何在不改变上游的情况下控制 Nginx 反向代理的缓存?