I want to update a custom timestamp field and therefore wrote this function
public function touchDelivery() {
$this->delivery = $this->freshTimestamp();
return $this->save();
}
public function pushSuccess($id) {
return Message::where('id', '=', $id)->touchDelivery();
}
But when executing Laravel complains:
Call to undefined method Illuminate\Database\Query\Builder::touchDelivery()
I am guessing that this code is in your Eloquent file. There's problem with return Message::where('id', '=', $id)->touchDelivery();
First you need to get all the messages and then for each messages, you need to call the method. Something like this.
public function pushSuccess($id) {
$messages = Message::where('id', '=', $id)->get();
foreach($messages as $message)
$message->touchDelivery();
...
}
Let me know if that works for you.