I\'m getting this weird error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column \'0\' in \'field list\' (SQL: update
forum_threads
set
As I mentioned in the comment section, change your function to this:
public function scopeLock($query)
{
return $query->where('locked', 0)->update(['locked' => 1]);
}
Note the changes in the update method.
in my case the problem was in the model attributes.I use protected $fillable, protect $foreignKey, protected $timestamp. to solve de problem, I put all the attributes in protect $fillable variable.
The error is due to ->update(['locked', 1]);
which should be ->update(['locked' => 1]);
the update function uses an array as "column" => "value", your syntax error causes Laravel to think [ 0 => 'locked', 1 => 1]
, so it translates to this SQL SET 0 = 'locked', 1 = 1
...
I had a double condition in WHERE
ContestPool::where(['contest_id', '=', $contest_id], ['user_id', '=', $user_id])->delete();
I fixed adding brackets for both conditions
ContestPool::where([['contest_id', '=', $contest_id], ['user_id', '=', $user_id]])->delete();