我想向我的rest api添加查询参数。我在资源集合中创建了它,现在找不到添加此功能的方法。每个教程都是关于创建api的其他方式的。我想通过产品代码向端点/ api / v1 / product进行过滤,如下所示: / api / v1 / product?product_code = 0208588343711。这是我的代码
产品负责人:
public function index(): ProductCollection
{
return new ProductCollection(Product::paginate());
}
ProductCollection
class ProductCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}