Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

colbyalbo's avatar

Trying to find DB::raw() alternative

Hello, I am trying to find a way not to use DB::raw() in the following method.

The Parent model is called Sessions, which has time and capacity fields, and a has many relationship with Schedules.

I am wondering if there is a way to access the values of the table columns with any built-in Eloquent methods, instead of DB::raw(). So far this is the only way I've worked it out :

   public function updateSchedules(): void
   {
       $time = Carbon::parse($this->time)->format('H:i:s');
       $max = $this->capacity;

// I'm updating the 'when' field with only the date part, then tacking on the updated time

// Also I am trying to update the value of 'max' with another columns current value, 'booked'

       $this->schedules()->where('booked', '>', $max)
           ->update([
               'when' => DB::raw("CONCAT(DATE(`when`), ' {$time}')"),
               'max' => DB::raw("booked"),
           ]);
   }
0 likes
2 replies

Please or to participate in this conversation.