Count in update query doesn't work in Laravel

emas94
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']);
nakov

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().

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Update manager doesn't work

分類Dev

UILabel int count ++ doesn't work

分類Dev

SQL Update doesn't work with Group by

分類Dev

SQL query in Crystal Reports doesn't update

分類Dev

Why doesn't this Mongoose query work?

分類Dev

LINQ search query doesn't work

分類Dev

Multiple-monitor display doesn't work after update to 13.10

分類Dev

PostgreSQL 9.5 - update doesn't work when merging NULL with JSON

分類Dev

oracle update table field with a defined function doesn't work

分類Dev

Spring Boot Query annotation with nativeQuery doesn't work in Postgresql

分類Dev

MYSQL data insert query doesn't work in Python

分類Dev

MySQL doesn't work properly when query is very big

分類Dev

ArangoDB - Query doesn't work in FOXX but works in web interface

分類Dev

Laravel 5.4 : Listening For Notifications doesn't work with me

分類Dev

The validation in api doesn't work in postman for my laravel project

分類Dev

phpunit command doesn't work for laravel 4 on windows 7

分類Dev

Parse : Trying multiple query in a function of Parse Cloud code. Second query doesn't seem to work

分類Dev

setViewControllers doesn't work

分類Dev

GitGutter doesn't work

分類Dev

Shown doesn't work

分類Dev

Crontab doesn't work

分類Dev

hidesBarsOnSwipe doesn't work

分類Dev

core data to-many relationship set count doesn't update until app restart

分類Dev

Update model with TryUpdateModel in ASP.NET MVC Core Web API and Entity Framework Core doesn't work

分類Dev

Mongoose Middleware pre 'remove' doesn't work, Model.update is not a function

分類Dev

Enter/update/exit join pattern Bostock example doesn't seem to work with new data "inserted" at position 0

分類Dev

apt-get update doesn't work after installation in kali rolling 2016

分類Dev

Laravel update() method yielding 'x doesn't have a default value' error

分類Dev

SwiftUI View doesn't update

Related 関連記事

  1. 1

    Update manager doesn't work

  2. 2

    UILabel int count ++ doesn't work

  3. 3

    SQL Update doesn't work with Group by

  4. 4

    SQL query in Crystal Reports doesn't update

  5. 5

    Why doesn't this Mongoose query work?

  6. 6

    LINQ search query doesn't work

  7. 7

    Multiple-monitor display doesn't work after update to 13.10

  8. 8

    PostgreSQL 9.5 - update doesn't work when merging NULL with JSON

  9. 9

    oracle update table field with a defined function doesn't work

  10. 10

    Spring Boot Query annotation with nativeQuery doesn't work in Postgresql

  11. 11

    MYSQL data insert query doesn't work in Python

  12. 12

    MySQL doesn't work properly when query is very big

  13. 13

    ArangoDB - Query doesn't work in FOXX but works in web interface

  14. 14

    Laravel 5.4 : Listening For Notifications doesn't work with me

  15. 15

    The validation in api doesn't work in postman for my laravel project

  16. 16

    phpunit command doesn't work for laravel 4 on windows 7

  17. 17

    Parse : Trying multiple query in a function of Parse Cloud code. Second query doesn't seem to work

  18. 18

    setViewControllers doesn't work

  19. 19

    GitGutter doesn't work

  20. 20

    Shown doesn't work

  21. 21

    Crontab doesn't work

  22. 22

    hidesBarsOnSwipe doesn't work

  23. 23

    core data to-many relationship set count doesn't update until app restart

  24. 24

    Update model with TryUpdateModel in ASP.NET MVC Core Web API and Entity Framework Core doesn't work

  25. 25

    Mongoose Middleware pre 'remove' doesn't work, Model.update is not a function

  26. 26

    Enter/update/exit join pattern Bostock example doesn't seem to work with new data "inserted" at position 0

  27. 27

    apt-get update doesn't work after installation in kali rolling 2016

  28. 28

    Laravel update() method yielding 'x doesn't have a default value' error

  29. 29

    SwiftUI View doesn't update

ホットタグ

アーカイブ