1 year ago

Validating a key in Request when it exists in certain Routes.

Posted 1 year ago by construct

Is there a correct away to validate a $request->get('key') only when it exists on a certain route being post or get? I was looking at Rules but I am not sure of how to implement it for every route that requires this key.

What I am trying to do is if $request->has('id'), then validate with a custom class.. i.e.

//if this param is passed on post/get on specific routes, check it..
if ($request->has('id')) {

    $isvalid = new IsThisIdInOurDatabase($request->get('id'));

    return $isvalid ? $isvalid : 'error: We could not find this product';

Please sign in or create an account to participate in this conversation.