我正在尝试链接多个查询构建器方法。一切正常,但是当我使用get()方法返回响应时,响应没有任何内容。 请求-GET / accounts?sort = name desc,created_at desc 这是我的控制器:
use SortedCollection;
protected $sortableAttributes = ["name", "created_at"];
public function __invoke(Request $request)
{
if ($request->sort != null) :
$validSortPairs = $this->validateSortQueryParam($this->sortableAttributes, $request->sort);
$queryBuilder = Account::query();
$databaseSortQuery = $this->getDatabaseSortQuery($validSortPairs, $queryBuilder);
return $databaseSortQuery->get();
endif;
}
这是我的SortedCollection特性:
public function getDatabaseSortQuery($validatedSortPairs, QueryBuilder $queryBuilder)
{
foreach ($validatedSortPairs as $key => $sortPair) {
$queryBuilder->orderBy($sortPair["sortAttribute"], $sortPair["sortOrder"]);
}
return $queryBuilder;
}