我在我的Laravel
项目中使用如下查询来获取数据:
-> Blog::where('status', 1)->where('title', 'like', '%'.$term.'%')->paginate(6);
现在我使用Laravel+Lighthouse-php
作为我的后端应用程序接口。
如何在Lighthouse-PHP
中编写此查询
发布于 2020-10-23 16:32:44
您可以在模型中使用Eloquent Scopes来确定状态条件的范围:
public function scopeEnabledBlogs($query) {
return $query->where('status', 1);
}
在您的模式中使用:
extend type Query {
Blogs(title: String @where(operator: "like")): [Blog!] @paginate(scopes: ["enabledBlogs"])
}
现在您可以查询您的博客,如下所示:
query {
Blogs(first: 6 title: "%something%") {
data {
title
}
}
}
https://stackoverflow.com/questions/64493218
复制相似问题