spatie / laravel-query-builder

Easily build Eloquent queries from API requests
https://spatie.be/docs/laravel-query-builder
MIT License
4k stars 392 forks source link

Query Telescope #950

Open elvispdosreis opened 2 months ago

elvispdosreis commented 2 months ago

the query was completely different and complex, despite bringing the result

query telescope

{
 "filter": 
  {
   "cidade.id": "3549805",
   "nome": "santa"
  }
}
select
  "id",
  "nome",
  "cidade_id",
  "bairro_id"
from
  "geral"."logradouros"
where
  LOWER("geral"."logradouros"."nome") LIKE ? ESCAPE '\' and exists (select * from "geral"."cidades" where "geral"."logradouros"."cidade_id" = "geral"."cidades"."id" and "geral"."cidades"."id" = ' % santa % ') and "geral"."logradouros"."deleted_at" is null order by "geral"."logradouros"."id" asc limit 51
 public function index(): JsonResponse
    {
        $logradouro = Logradouro::select(['id', 'nome', 'cidade_id', 'bairro_id']);
        $logradouro = QueryBuilder::for($logradouro);
        $logradouro->allowedFilters(
            AllowedFilter::exact('id'),
            AllowedFilter::partial('nome', null, false),
            AllowedFilter::exact('cidade.id'),
            AllowedFilter::exact('bairro.id'),
            AllowedFilter::scope('keyword'),
        );

        return response()->json($logradouro->cursorPaginate(50)->withQueryString());
    }