lundi 25 décembre 2017

Passing variables between controllers and returning (PHP)

Probably is a very easy question, but I'm new and after trying to find a similar I'm still unsure:

So I have an AJAX form pointing to:

function postLogin(Request $request){
   $this->fatherAuth($request); 

   return response() -> json(['url' => '/login-ok',], 200); 
}

Then I have:

public function fatherAuth($request){

    $validator = Validator::make($request->all(), [
        'email' => 'required|email',
    ],[
         'email.required' => 'Email needed',
    ]);

    # do some other checks and if there's some auth error:# 
    return response() -> json(['url' => '/login-bad',], 400); 
}

So what's happening is that I'm always getting the 200 response instead of the 400.

Should I pass a variable to postLogin? Should I send it to a new function?

BTW the reason of creating fatherAuth is because this code is shared between several controllers.

What would be the best solution / best practice?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire