1
if($key == "postcode") {
    $this->validate($request, [
    'postcode' => ['required','regex:#^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$#'],
    ]);
}

I need to convert the postcode field into uppercase before I pass it in to this validate function. I tried $request->input('postcode') = strtoupper($request->input('postcode')); but got;

Can't use method return value in write context.

I want to keep $request as the whole Request object ideally. Otherwise I’d just pass in the $request->input('postcode') on it's own. Actually I think the method is type-hinted for Request.

This is Laravel 5.1

0

1 Answer 1

2

You could do it with the merge method:

$request->merge(array('postcode' => strtoupper($request->input('postcode'))));

Maybe it is also interesting to know that you can make your validation case-insensitive, by adding the i modifier at the end of the regular expression:

#^(GIR .... $#i
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.