1
public function increment($id) { $this->model->where("id",'=', $id)->update(['rating'=> DB::raw('count+1')]); } 

I am getting the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'count' in 'field list' (SQL: update news set rating = count+1, updated_at = 2019-04-13 08:12:51 where id = 5)

I also tried

->update(['rating'=>'count+1']); 

1 Answer 1

3

You are not telling the query builder on which table you are performing the query, so DB::raw('count+1') makes no sense.

You can try to use the eloquent increment method like this:

$this->model->where("id", $id)->increment('rating'); 

Thanks @Tharaka removed the extra call to save().

Sign up to request clarification or add additional context in comments.

2 Comments

hah i tried it last time but i made stupid mistake, thank you for this, it work. But in last line must be update(). Thanks
and, you don't have to call save(). it automatically saves to the database.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.