1 month ago

Laravel trim problem

Posted 1 month ago by ipibk

there is a table of shops, in it, we store URLs with HTTP and https already cut off. example: rozetka.ua, comfy.ua from the front to the request for validation, the URL that has not yet been processed arrives, with HTTP or https. For example http://rozetka.ua

How to check the site for uniqueness? validation have a check for URL, the option with preliminary HTTP is not suitable.

Since the site has already been configured to work with errors and interception of front-line and back-validation, it is necessary to achieve the condition that when validating the request it is an error as if unique. That is the status 422 and the corresponding error object. So far I have stayed on this option:

return [
    'url' => [
        function ($attribute, $value, $fail) {
           $url = parse_url($value, PHP_URL_HOST);
           if (Store::where('url', $url)->count() > 0) {
              $fail('The ' . $attribute . ' has already been taken.');

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