1

I am checking working on an invites only platform. You need to enter a valid token to get on board.

only the first token validates, any other token in the table is not even checked. What will be the best way to structure this to check all the tokens and only go to the else statement after checking the array.

    $this->validate($request,['pin' => 'required|numeric|digits:6']);

    $token = $request->input('pin');


    $all_pins  = \App\Pin::all()->toArray();
     if (in_array($token,$all_pins,true))
        {

            $user  = Auth::user()->id;
            $user = $this->user->find($user);
            $user->pin = $token;
            $user->is_activated = true;
            $user->has_pin = true;
            $user->save();

            flash('Your Pin was valid, Welcome', 'success');
            return redirect()->route('token_page');

        }

        else
        {
            flash('Sorry this pin is not valid', 'warning');
            return redirect()->route('reg_token_check');
        }`

`

4
  • 1
    show the output of $token and $all_pins Commented May 11, 2017 at 11:34
  • I dd that and they were valid. what am trying to say that it should check all, but in this case, when it checks one and its not valid, it returns the else statement Commented May 11, 2017 at 11:38
  • do you have one line space before else ? Commented May 11, 2017 at 11:39
  • you might not get it with that. becaues in_array will check once only. wait will give you one soultion Commented May 11, 2017 at 11:41

1 Answer 1

2
foreach($all_pins as $value){
if($token == $value){
//do if part
    }
else{
//do else part
    }
}

try this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.