首页 > 解决方案 > 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

标签: phplaravel

解决方案


更改您的网址:

http://localhost:8000/api/products/16

还要更改视图文件:

<a href="{{ URL::to('products/'. $yourchategoryid ) }}">product</a>

推荐阅读