search

Home  >  Q&A  >  body text

get parameter validation in Laravel

Could you please tell me how to verify the parameters passed by get in laravel

There are many filtering conditions at the top of the order list page, but these filtering conditions have certain rules. For example, the amount must be a number, and the user name cannot be greater than 5 digits.
If parameters are passed to the background through get for conditional filtering, the url address and How to verify that it is the same when no parameters are passed?

If verification is performed, if the user comes in without any filtering conditions at the beginning, the verification will fail directly

大家讲道理大家讲道理2751 days ago508

reply all(3)I'll reply

  • 迷茫

    迷茫2017-05-16 16:49:29

    One solution is to add an area to display errors on the page and display it using the method provided by Laravel (submit the form directly, use js to verify whether the information is legal before submitting, submit after the js verification passes, and then verify it on the backend)

    @if ($errors->count() > 0)
        {{ $errors->first($errors->keys()[0] ?? null) }}
    @endif
    

    However, this method is not very friendly. You can change the screening form submission to asynchronous, and use js to render the page results.

    reply
    0
  • 阿神

    阿神2017-05-16 16:49:29

    Parameter filtering rules?
    Use middleware decisively, get the get parameter request, $request->getQueryString(), and then put it in the middleware for screening.

    reply
    0
  • PHPz

    PHPz2017-05-16 16:49:29

    Don’t verify the format if there are no parameters passed in.
    Verify only after passing the parameters.

    reply
    0
  • Cancelreply