Level 70
@colbyalbo Maybe using updateExistingPivot()?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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"),
]);
}
Please or to participate in this conversation.