lundi 30 mai 2016

Laravel - Getting error when incrementing table field value

I am updating number of views count when user reloads the page and I have written this code:

public function index()
{
    $ProjectIdx = str_slug(Request::segment(2), "-"); // Getting page id
    if(ctype_digit($ProjectIdx)) {
        DB::table('project')
            ->where('ProjectIdx', $ProjectIdx)
            ->increment('NumViews');
    }
}

but when the count is greater than 99 I am getting this error:

QueryException in Connection.php line 651:

SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 (SQL: update `project` set `NumViews` = `NumViews` + 1 where `ProjectIdx` = 511)

Table structure:

Name        Type
----------  -------
ProjectIdx  int(11)
NumViews    int(11)

Any Idea?

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire