Support the ongoing development of Laravel.io →
Database Eloquent

Hey guys,

Been trying to come with solution to translate this query as eloquent as possible, but keep PDOExceptioning; I'm using postgresql and using a migration class that will update jobs table.

i need to go over all records and update the end date if it is not in one year minus one day from start date.

query:


UPDATE jobs SET (start, end) = (start, start + interval '1 year' - interval '1 day')    
WHERE start + interval '1 year' - interval '1 day' != end;

wishful thinking:

DB::table('jobs')
  ->where( ?? , '<>', ??)
  ->update([
     'start' => DB::raw('start'),
     'end' => Carbon::parse(DB::raw('start'))->addYear()->subDay()
  ]);  

For now, unfortunately, i have no working solution, so any help/pointer to get me going would be more than appreciated.

Thank you in advance.

Last updated 2 years ago.
0

Can't you use something like

->whereRaw("start + interval '1 year' - interval '1 day' != end")

Hope that helps

Joel

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mishkez mishkez Joined 24 Jan 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.