Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
¿Cómo puedo consultar todo, ordenar y paginar?

ingrese la descripción de la imagen aquí

No sé cuál es el problema con mi consulta, pero el conteo claramente está mal, seguía mostrándose como 1912 cuando mis registros totales son 12363


Lo intenté

para cambiar esta línea en mi caso predeterminado

 $q = Visitor::where('created_at', '<', now());

para

 $q = Visitor::all(); but I got error;

El método Illuminate\Database\Eloquent\Collection::orderBy no existe.


 switch ($interval) { case 'day': $q = Visitor::where('created_at', '>', now()->today()); break; case 'week': $q = Visitor::where('created_at', '>', now()->subWeek()); break; case 'month': $q = Visitor::where('created_at', '>', now()->subMonth()); break; case 'year': $q = Visitor::where('created_at', '>', now()->subYear()); break; case 'last': $q = Visitor::where('created_at', '>', $last); break; default: $q = Visitor::where('created_at', '<', now()); break; } $visitors = $q->orderBy('created_at', 'desc')->paginate(15);

http://app.test/visitor?interval=año

Obtuve 1912 - correcto 👍🏽


http://aplicación.prueba/visitante

Obtuve 1912 - no es correcto ❌, debería consultar todo ya que no se especifica el intervalo.

Si lo hago :

 dd(count(Visitor::all()));

12363 , por lo que debería ser el valor correcto.

Por favor, avíseme si ve lo que me perdí.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

$q = Visitor::all(); devuelve Illuminate\Database\Eloquent\Collection .

Llamando $visitors = $q->orderBy('created_at', 'desc')->paginate(15); llamará a ->orderBy(...) en una Eloquent Collection de la cual ese método no existe en esa clase.

Solución

En vez de:

 $q = Visitor::where('created_at', '<', now()); ❌

Utilizar esta:

 $q = Visitor::query(); ✅
over 4 years ago · Santiago Trujillo Report

0

Tal vez pueda usar ->whereDate('created_at', now()) , con ->whereTime('created_at', '00:00:00') si lo necesita

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!