Reputation: 33
Why my Laravel mutator does't work? I want to increment values in "like" column. Commented row works good, but mutator doesn't instead of commented one.
public function updateLike(Request $request){
$comment = Comment::find($request->id);
//$comment -> like = $comment-> like + 1;
$comment -> save();
}
public function setLikeAttribute($value){
return $this -> like = $value + 1;
}
Upvotes: 0
Views: 351
Reputation: 779
you need use this in mutator
$this->attributes['like'] = $value + 1;
but for your case, mutator is not used for automatically increase a value, you should use your commented code, not mutator.
Upvotes: 1