Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marnixk77's avatar

Disable validation on get request

Hi,

I am having a controller that I need the access with post and get routing. The post request is getting userinfo to login to a api. The get request is used the redirect back after an error from a link on the page.

But when I redirect back to the page with a get request is gets into a loop. Is there an option to disable the validation request when I use the get method ?

Function inside the controller

  public function select(BsLogin $request)
    {
 	<<code>>       
    }

BSlogin is a request validator with some basic rules in it.

Do I need to remove it from this position and move in in the function and check if there is a post or get request and only do the validation on the post request ? And if so how can I use the external request file for validation inside the function.

0 likes
2 replies
MichalOravec's avatar

Inside BsLogin

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    if ($this->isMethod('post')) {
        return [
            // your rules
        ];
    }
    
    return []; // empty array for get request
}
bestmomo's avatar

Why don't you use distinct function for distinct methods ?

Please or to participate in this conversation.