Skip to content

Conversation

@farah-darzaid
Copy link

No description provided.

$voice->update([
'value'=>$request->post('value')

private $user;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value use only in one method, better make as local


public function voice(Request $request)
{
$this->usre = Auth::user();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake "$this->usre"
better to use $userId = Auth::id();

'value' => 'required|boolean',
]);

$question = Question::findOrfail($request->question_id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never fail, we already validate "exists:questions,id"

]);
} else if (($voice) && $voice->value !== $request->value) {
//update or create first param is the condition of match values, second indicate fields to be updated
$voice->updateOrCreate([
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$voice exists, we don't need create record

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this parameters user will vote 2 times

$question = Question::findOrfail($request->question_id);
if ($question->user_id == $this->user->id)
return response()->json([
'status' => 500,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status code must be 401 "Unauthorized"

]);
}

return response()->json([
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't check !$voice. If record didn't exist we can't vote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants