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

336
Views
Pass dynamic value from database to Carbon::now()->subMinutes()

I have a minutes integer column in the db,any way to make the below query work without an additional query? Laravel 8 if it matters.

Contest::latest()->where('created_at','>',  Carbon::now()->subMinutes('minutes')->toDateTimeString())->paginate(4)

;

Reponse ErrorException: A non-numeric value encountered in file

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You cannot do this without an additional query. Carbon is a PHP library and won't work within the SQL query. However SQL does provide native functionality for what you need to do:

Contest::latest()
    ->where('created_at','>', DB::raw('NOW()-INTERVAL minutes MINUTE'))->paginate(4)

This should generally work though you may need to replace NOW() with whatever the DBMS provides if not using MySQL.

over 4 years ago · Santiago Trujillo Report

0

From seeing documentation, I can see that the method subMinutes() accepts integer as a parameter, not string. Maybe try fixing that one first. When I try Carbon::now()->subMinutes('minutes')->toDateTimeString() running locally, I get a similar error: A non-numeric value encountered.

Information about addition and subtraction of Carbon can be found here

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!