I want to add 1 to my previous karma value in my database.
Here's what I am doing in my controller:-
public function response(Request $request, $id)
{
$globalPost = PublicAnswer::find($id);
if($request->resp == "normal")
{
$answered_by = DB::table('users')
->where('id', $globalPost->answered_by)
->increment('karma', +1);
}
}
Here's my database:-
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('karma')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
If I replace increment function with update this is the error that I am getting:-
Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given,
I cannot see any errors and the karma attribute is null.
can anyone tell me whats wrong with my codes.