{"id":323025,"date":"2021-05-13T09:00:50","date_gmt":"2021-05-13T09:00:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=323025"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=323025","title":{"rendered":"\u0414\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f Form Request \u0432 Laravel"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443  \u043a\u0430\u043a \u0438 \u0437\u0430\u0447\u0435\u043c \u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432 Laravel.<\/p>\n<h2>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Form Request<\/h2>\n<p><strong>Form Request <\/strong>&#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0433\u0434\u0435 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0431\u044b\u0447\u043d\u043e  \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b \u043f\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432 Laravel  \u043e\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u043d\u0430\u0448\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. Form Request \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">namespace App\\Http\\Requests;  use Illuminate\\Foundation\\Http\\FormRequest;  class UpdateUserProfile extends FormRequest { \tpublic function rules(): array   {    return [ \t\t'email' =&gt; ['required', 'email'], \t\t'name'  =&gt; ['required', 'alpha'], \t\t'age'   =&gt; ['integer', 'max:120'], \t ];   } \t \tpublic function messages():array \t{ \t\treturn [ \t\t 'email.required' =&gt; 'Email \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c email' \t\t]; \t} }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0437\u043d\u0430\u043a\u043e\u043c\u043e \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e. \u0421\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u044f \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043b \u043d\u0438\u0436\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442. \u0412\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c Form Request \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438 \u0438 \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e \u043a\u0430\u043a <strong>\u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e <\/strong>\u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439&#8230;<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/27f\/621\/a7f\/27f621a7f9264fcd86e44c6315b1901f.jpg\" width=\"3086\" height=\"2182\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e, \u0434\u0430\u0432\u0430\u0439-\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0431\u043e\u0442\u0430 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0438 \u0437\u0434\u0435\u0441\u044c. \u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435.<\/p>\n<p>\u0411\u043e\u0442 \u0437\u0430\u0434\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u0441\u0440\u0430\u0437\u0443 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0445 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0411\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e &#8212; \u0435\u0441\u043b\u0438  \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u043e\u0442 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 &#171;\u0435mail \u0431\u044b\u043b \u043d\u0435 \u0432\u0435\u0440\u043d\u044b\u0439&#187;. \u0412 \u043c\u043e\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0431\u043e\u0442 \u0432\u0435\u0434\u0435\u0442 \u0434\u0438\u0430\u043b\u043e\u0433, \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044f \u0432\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041a\u0430\u043a Form Request \u0440\u0435\u0448\u0438\u0442 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443?<\/h2>\n<p>\u0418\u0442\u0430\u043a \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d Form Request \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0438\u0437 \u0441\u0430\u0439\u0442\u0430.<\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448 Form Request \u043f\u043e\u0434 \u043d\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430(\u043d\u043e \u044d\u0442\u043e \u0448\u0430\u043d\u0441 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435). \u0415\u0449\u0435 \u043c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0434\u0432\u0443\u0445\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0435\u043d \u0438 \u043d\u0435\u0447\u0438\u0442\u0430\u0435\u043c. \u0412\u043d\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u044b(\u0438\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0430) \u043f\u043e\u0437\u0436\u0435 \u043d\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u0447\u0442\u043e \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u043a\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e. \u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 &#171;Don&#8217;t repeat yourself&#187;. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e(\u0430 \u043e\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0435\u0442), \u0442\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0436\u0435 \u0432 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"php\">public function store(Request $request) { \t$validated = $request-&gt;validate([ \t\t'email' =&gt; ['required', 'email']   ]); }<\/code><\/pre>\n<h2>\u0414\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0434\u0435\u044f, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435(<strong>field<\/strong>) \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 <strong>ValidatorValue<\/strong>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dba\/7d7\/0da\/dba7d70dae28bc151363a390475f49a0.jpg\" width=\"3086\" height=\"2182\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 Form Request. <\/p>\n<pre><code class=\"php\">class UpdateUserProfile extends FormRequestDecompose { \tpublic function rules(): array   {    return [ \t\tnew UserEmail(auth()-&gt;user()-&gt;id), \t\tnew UserName(), \t\tnew UserAge(), \t ];   } }<\/code><\/pre>\n<ul>\n<li>\n<p> \u041c\u044b \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043e\u0442 \u043c\u043e\u0435\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e  \u043a\u043b\u0430\u0441\u0441\u0430 <strong>FormRequestDecompose<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0435\u043a\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <strong>ValidatorValue<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0430\u0432\u0438\u043b, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447 \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0430\u0432\u0438\u043b \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430(\u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430)<\/p>\n<\/li>\n<\/ul>\n<h2>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h2>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <strong>ValidatorValue. <\/strong>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0415\u0449\u0435 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u0435\u0441\u043b\u0438 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043d\u043e \u044d\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0443\u0436\u0435 \u043a\u043e\u0434\u0430. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getRules<\/strong> \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getMessages <\/strong>\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430(\u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442\u0441\u044f).<\/p>\n<pre><code class=\"php\">class UserEmail implements ValidatorValue { \tprivate $attribute; \t \tprivate $exceptUserId;      public function __construct(int $userId, string $attribute = 'email') \t{ \t\t$this-&gt;exceptUserId = $userId; \t\t$this-&gt;attribute = $attribute; \t}  \tpublic function getAttribute(): string \t{ \t\treturn $this-&gt;attribute; \t} \t \t    public function getRules(): array     {         return [             'required',             'email',             \"unique:users,email,{$this-&gt;exceptUserId}\",         ];     }      public function getMessages(): array     {         return [             \"{$this-&gt;attribute}.email\"         =&gt; '\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 email',             \"{$this-&gt;attribute}.required\"      =&gt; '\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0443\u043a\u0430\u0436\u0438\u0442\u0435 email',             \"{$this-&gt;attribute}.unique\"        =&gt; 'Email \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0433\u0435\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d'         ];     } }<\/code><\/pre>\n<pre><code class=\"php\">interface ValidatorValue {     \/**      * Should return list rules      * @example ['required','email','unique:users,email'];      * @return array      *\/     public function getRules(): array;      \/**      * @return string      *\/     public function getAttribute(): string;      \/**      * @return array      *\/     public function getMessages(): array; }<\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0431\u043e\u0442\u0430?<\/strong><\/p>\n<p> \u0412 Laravel \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e BotMan, \u044d\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u0442\u0430\u043c\u0438 \u0438 \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 Laravel.<br \/>\u0418\u0442\u0430\u043a, \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Facade \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0412\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"php\">$validatorUserEmail = UserEmail(auth()-&gt;user()-&gt;id);  $this-&gt;validator = Validator::make([ \t\t$validatorUserEmail-&gt;getAttribute() =&gt; $answerFromUser ],[ \t$validatorUserEmail-&gt;getAttribute() =&gt; $validatorUserEmail-&gt;getRules() ], \t$validatorUserEmail-&gt;getMessages()); if ($this-&gt;validator-&gt;fails() === false) { \t\t\/\/ ... }<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043c\u0435\u0447\u0442\u0430\u043b\u0438.<br \/>\u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0438  \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u044f\u0449\u043d\u043e:<\/p>\n<pre><code class=\"php\">if ($this-&gt;validate($answer-&gt;getText(), new UserEmail($this-&gt;user-&gt;id)) {    \/\/ ... }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u043a \u0438 \u0432\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435, \u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 <strong>FormRequestDecompose<\/strong>, \u0434\u043b\u044f \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0432 Form Request \u0442\u0430\u043a \u0438 \u043f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: ConsumerEmail, SellerPersonalPhone.<\/p>\n<p>\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u0438 \u043b\u044e\u0431\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u044f \u0441\u043e\u0437\u0434\u0430\u043b <a href=\"https:\/\/github.com\/agoalofalife\/decompose-validator\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>.  \u041a\u043e\u0434 \u0442\u0430\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0434 \u0441\u0435\u0431\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0441 \u043f\u043e\u0445\u043e\u0436\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043a\u0430\u043a \u0435\u0435 \u0440\u0435\u0448\u0430\u043b\u0438.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/557156\/\"> https:\/\/habr.com\/ru\/post\/557156\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443  \u043a\u0430\u043a \u0438 \u0437\u0430\u0447\u0435\u043c \u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432 Laravel.<\/p>\n<h2>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Form Request<\/h2>\n<p><strong>Form Request <\/strong>&#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0433\u0434\u0435 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0431\u044b\u0447\u043d\u043e  \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b \u043f\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432 Laravel  \u043e\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u043d\u0430\u0448\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. Form Request \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">namespace App\\Http\\Requests;  use Illuminate\\Foundation\\Http\\FormRequest;  class UpdateUserProfile extends FormRequest { \tpublic function rules(): array   {    return [ \t\t'email' =&gt; ['required', 'email'], \t\t'name'  =&gt; ['required', 'alpha'], \t\t'age'   =&gt; ['integer', 'max:120'], \t ];   } \t \tpublic function messages():array \t{ \t\treturn [ \t\t 'email.required' =&gt; 'Email \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c email' \t\t]; \t} }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0437\u043d\u0430\u043a\u043e\u043c\u043e \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e. \u0421\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u044f \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043b \u043d\u0438\u0436\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442. \u0412\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c Form Request \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438 \u0438 \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e \u043a\u0430\u043a <strong>\u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e <\/strong>\u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439&#8230;<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e, \u0434\u0430\u0432\u0430\u0439-\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0431\u043e\u0442\u0430 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0438 \u0437\u0434\u0435\u0441\u044c. \u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u043e\u0442\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435.<\/p>\n<p>\u0411\u043e\u0442 \u0437\u0430\u0434\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u0441\u0440\u0430\u0437\u0443 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0445 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0411\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e &#8212; \u0435\u0441\u043b\u0438  \u0432 \u043a\u043e\u043d\u0446\u0435 \u0431\u043e\u0442 \u0441\u043e\u043e\u0431\u0449\u0438\u0442 &#171;\u0435mail \u0431\u044b\u043b \u043d\u0435 \u0432\u0435\u0440\u043d\u044b\u0439&#187;. \u0412 \u043c\u043e\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0431\u043e\u0442 \u0432\u0435\u0434\u0435\u0442 \u0434\u0438\u0430\u043b\u043e\u0433, \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u044f \u0432\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041a\u0430\u043a Form Request \u0440\u0435\u0448\u0438\u0442 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443?<\/h2>\n<p>\u0418\u0442\u0430\u043a \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d Form Request \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0438\u0437 \u0441\u0430\u0439\u0442\u0430.<\/p>\n<ul>\n<li>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448 Form Request \u043f\u043e\u0434 \u043d\u0430\u0448\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430(\u043d\u043e \u044d\u0442\u043e \u0448\u0430\u043d\u0441 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435). \u0415\u0449\u0435 \u043c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0434\u0432\u0443\u0445\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0435\u043d \u0438 \u043d\u0435\u0447\u0438\u0442\u0430\u0435\u043c. \u0412\u043d\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u044b(\u0438\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0430) \u043f\u043e\u0437\u0436\u0435 \u043d\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u0447\u0442\u043e \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u043a\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e. \u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 &#171;Don&#8217;t repeat yourself&#187;. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e(\u0430 \u043e\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0435\u0442), \u0442\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0436\u0435 \u0432 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"php\">public function store(Request $request) { \t$validated = $request-&gt;validate([ \t\t'email' =&gt; ['required', 'email']   ]); }<\/code><\/pre>\n<h2>\u0414\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041c\u043d\u0435 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043f\u0440\u0438\u0448\u043b\u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0434\u0435\u044f, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435(<strong>field<\/strong>) \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 <strong>ValidatorValue<\/strong>.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 Form Request. <\/p>\n<pre><code class=\"php\">class UpdateUserProfile extends FormRequestDecompose { \tpublic function rules(): array   {    return [ \t\tnew UserEmail(auth()-&gt;user()-&gt;id), \t\tnew UserName(), \t\tnew UserAge(), \t ];   } }<\/code><\/pre>\n<ul>\n<li>\n<p> \u041c\u044b \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043e\u0442 \u043c\u043e\u0435\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e  \u043a\u043b\u0430\u0441\u0441\u0430 <strong>FormRequestDecompose<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0435\u043a\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <strong>ValidatorValue<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0430\u0432\u0438\u043b, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447 \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0430\u0432\u0438\u043b \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430(\u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430)<\/p>\n<\/li>\n<\/ul>\n<h2>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h2>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <strong>ValidatorValue. <\/strong>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0415\u0449\u0435 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u0435\u0441\u043b\u0438 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043d\u043e \u044d\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0443\u0436\u0435 \u043a\u043e\u0434\u0430. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getRules<\/strong> \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getMessages <\/strong>\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430(\u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442\u0441\u044f).<\/p>\n<pre><code class=\"php\">class UserEmail implements ValidatorValue { \tprivate $attribute; \t \tprivate $exceptUserId;      public function __construct(int $userId, string $attribute = 'email') \t{ \t\t$this-&gt;exceptUserId = $userId; \t\t$this-&gt;attribute = $attribute; \t}  \tpublic function getAttribute(): string \t{ \t\treturn $this-&gt;attribute; \t} \t \t    public function getRules(): array     {         return [             'required',             'email',             \"unique:users,email,{$this-&gt;exceptUserId}\",         ];     }      public function getMessages(): array     {         return [             \"{$this-&gt;attribute}.email\"         =&gt; '\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 email',             \"{$this-&gt;attribute}.required\"      =&gt; '\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0443\u043a\u0430\u0436\u0438\u0442\u0435 email',             \"{$this-&gt;attribute}.unique\"        =&gt; 'Email \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0433\u0435\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d'         ];     } }<\/code><\/pre>\n<pre><code class=\"php\">interface ValidatorValue {     \/**      * Should return list rules      * @example ['required','email','unique:users,email'];      * @return array      *\/     public function getRules(): array;      \/**      * @return string      *\/     public function getAttribute(): string;      \/**      * @return array      *\/     public function getMessages(): array; }<\/code><\/pre>\n<p><strong>\u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0431\u043e\u0442\u0430?<\/strong><\/p>\n<p> \u0412 Laravel \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e BotMan, \u044d\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u0442\u0430\u043c\u0438 \u0438 \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 Laravel.<br \/>\u0418\u0442\u0430\u043a, \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Facade \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0412\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"php\">$validatorUserEmail = UserEmail(auth()-&gt;user()-&gt;id);  $this-&gt;validator = Validator::make([ \t\t$validatorUserEmail-&gt;getAttribute() =&gt; $answerFromUser ],[ \t$validatorUserEmail-&gt;getAttribute() =&gt; $validatorUserEmail-&gt;getRules() ], \t$validatorUserEmail-&gt;getMessages()); if ($this-&gt;validator-&gt;fails() === false) { \t\t\/\/ ... }<\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043c\u0435\u0447\u0442\u0430\u043b\u0438.<br \/>\u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0438  \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u044f\u0449\u043d\u043e:<\/p>\n<pre><code class=\"php\">if ($this-&gt;validate($answer-&gt;getText(), new UserEmail($this-&gt;user-&gt;id)) {    \/\/ ... }<\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u043a \u0438 \u0432\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435, \u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 <strong>FormRequestDecompose<\/strong>, \u0434\u043b\u044f \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0432 Form Request \u0442\u0430\u043a \u0438 \u043f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: ConsumerEmail, SellerPersonalPhone.<\/p>\n<p>\u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043b\u0435\u043d\u0438\u0432\u044b\u0445 \u0438 \u043b\u044e\u0431\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u044f \u0441\u043e\u0437\u0434\u0430\u043b <a href=\"https:\/\/github.com\/agoalofalife\/decompose-validator\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>.  \u041a\u043e\u0434 \u0442\u0430\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0434 \u0441\u0435\u0431\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0441 \u043f\u043e\u0445\u043e\u0436\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043a\u0430\u043a \u0435\u0435 \u0440\u0435\u0448\u0430\u043b\u0438.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/557156\/\"> https:\/\/habr.com\/ru\/post\/557156\/<\/a><br \/><\/br><\/br><\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-323025","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=323025"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323025\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}