$position = getPositionLocation($id);
$extra = UserExtra::where('user_id', $posid)->first();
if ($position = 1) {
$extra->free_left += 1;
} else {
$extra->free_right += 2;
}
$extra->save();
This is were my error is
$extra->free_left += 1;
$extra->free_left +== 1;
2
Answers
Check if property free_left exists on the $extra object.
#1 – You can use is_null and the
!
, just to prevent thatNULL
error from$extra
.#2 – In laravel you can use the ->firstOrFail() to prevent this error without more condition on your code.