{"id":302123,"date":"2020-04-18T21:00:14","date_gmt":"2020-04-18T21:00:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=302123"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=302123","title":{"rendered":"\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0432 Laravel. \u0427\u0430\u0441\u0442\u044c 2. \u0428\u043b\u044e\u0437\u044b, \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/497834\/\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435 \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0425\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435.<br \/>  \u042f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0441\u0432\u043e\u0439 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0432 Laravel. \u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043e \u0447\u0435\u043c \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/post\/497220\/\">\u041f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c<\/a>.  <\/p>\n<p>  <\/p>\n<p> \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438: \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0433\u0438\u0431\u043a\u0443\u044e \u0438 \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0435\u0433\u043e \u0440\u043e\u043b\u0438.<br \/>   \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0441\u0432\u044f\u0437\u043a\u0438 \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430(Policy)&lt;=&gt;\u0428\u043b\u044e\u0437(Gate). \u0410 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0440\u0430\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<p>  <\/p>\n<p> \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0441\u0440\u0430\u0437\u0443 \u0443\u0442\u043e\u0447\u043d\u044e, \u0447\u0442\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443.  <\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0427\u0430\u0441\u0442\u044c 3. \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438(Policy), \u0428\u043b\u044e\u0437\u044b(Gate)<\/h2>\n<p>  <\/p>\n<h3>\u0422\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/h3>\n<p>  <\/p>\n<p> \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 \u0442\u0435\u043c\u0443 \u2014 \u00ab\u0427\u0442\u043e \u0436\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c <i>Policy<\/i> \u0438\u043b\u0438 <i>Gate<\/i>?\u00bb. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u0431\u044b\u0432\u0430\u043b \u0432 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0438, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c. \u041d\u043e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u2014 \u044d\u0442\u043e \u0434\u0432\u0430 \u0437\u0432\u0435\u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0446\u0435\u043f\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u044f\u0437\u043a\u0435.<br \/>   \u0412 Laravel \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0432\u044f\u0437\u043a\u0438 \u2014 \u0440\u0443\u0447\u043d\u0430\u044f \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f. \u0420\u0443\u0447\u043d\u0443\u044e \u044f \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0441\u0442\u0430\u043d\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u0432\u044f\u0437\u043a\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0435\u0441\u043e\u0438\u0437\u043c\u0435\u0440\u0438\u043c\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0441\u0438\u043b\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u043d\u0435\u0436\u0435\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439.  <\/p>\n<p>  <\/p>\n<p> \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438(\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f) \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0422\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0428\u043b\u044e\u0437\u044b(Gate) \u2014 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c. \u0415\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0442\u044c \u0432\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u044b \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0448\u043b\u044e\u0437\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0440\u0435\u0441\u0443\u0440\u0441 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <i>app<\/i>. \u0422\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0432 \u0431\u043e\u043b\u0435\u0435 \u0438\u043b\u0438 \u043c\u0435\u043d\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0442\u0430\u043a\u043e\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u043d\u043e\u0441\u0438\u0442 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0443\u044e \u043d\u0435\u0440\u0430\u0437\u0431\u0435\u0440\u0438\u0445\u0443 \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u043c \u0434\u0435\u0440\u0435\u0432\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u0441 \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u043c\u044b \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043f\u0430\u043f\u043a\u0443 <i>app\/Models<\/i>.  <\/p>\n<p>  <\/p>\n<p> \u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 <i>Gate::guessPolicyNamesUsing(&#8216;callback&#8217;)<\/i>. \u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0432 \u0442\u0435\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <i>boot()<\/i> \u043a\u043b\u0430\u0441\u0441\u0430 <i>App\\Providers\\AuthServiceProvider<\/i>(\u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430).  <\/p>\n<p>  <\/p>\n<h3>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435<\/h3>\n<p>  <\/p>\n<h4>Gate<\/h4>\n<p>  <\/p>\n<p> \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 (callback), \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u0430\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 <i>guessPolicyNamesUsing()<\/i> \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435, \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u0418\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u0449\u0430\u043c\u0438: \u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0435\u0439 \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u0438 <i>Policy<\/i> \u0432 \u043a\u043e\u043d\u0446\u0435. \u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u043e\u0441\u0442\u0440\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e \u043e\u0431 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 Laravel (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043c\u043e\u0436\u043d\u043e \u0435\u0433\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/alexeymezenin\/laravel-best-practices\/blob\/master\/russian.md\" rel=\"nofollow\">\u0432 \u044d\u0442\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>). \u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0440\u043e\u043b\u044c SuperAdmin \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0438 \u0442\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u2014 super-admin \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0435. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u2014 \u0442\u043e \u044d\u0442\u043e \u043d\u0438 \u043a \u0447\u0435\u043c\u0443.<br \/>   \u041d\u0430 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 PHP \u043d\u0438\u0436\u0435 7.4 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e. \u041d\u0430 7.4 \u0438 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0438 \u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0439.  <\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Providers;  use Illuminate\\Foundation\\Support\\Providers\\AuthServiceProvider as ServiceProvider; use Illuminate\\Support\\Facades\\Gate;  class AuthServiceProvider extends ServiceProvider {     public function boot()     {         $this-&gt;defineSuperAdmin();         $this-&gt;defineAutoDiscover();     }      private function defineAutoDiscover()     {         Gate::guessPolicyNamesUsing(function ($class) {             return str_replace(&quot;\\\\Models\\\\&quot;, &quot;\\\\Policies\\\\&quot; , $class) . 'Policy';         });     }      private function defineSuperAdmin()     {         Gate::before(function($user) {             return $user-&gt;hasRole('super-admin') ? true : null;         });     } } <\/code><\/pre>\n<p>  <\/p>\n<h4>Policy<\/h4>\n<p>  <\/p>\n<p> \u0418\u0442\u0430\u043a, \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0433\u0434\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:  <\/p>\n<p>  <\/p>\n<pre>     php artisan make:policy PostPolicy --model=Models\/Post <\/pre>\n<p>  <\/p>\n<p> \u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u041d\u043e \u043c\u044b \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0422\u0430\u043a \u043a\u0430\u043a \u044f \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0441\u044c \u0441\u0430\u043c, \u0438 \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 DRY,- \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u0442\u0438 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438. \u0410 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043e\u0442\u0434\u0430\u0442\u044c \u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043b\u0438\u0431\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u0442\u044c\u0438, \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <i>getModelClass()<\/i> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438. \u041c\u0435\u0442\u043e\u0434\u044b \u0436 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/497220\/\">\u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u044b<\/a> \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 \u043c\u043e\u0434\u0435\u043b\u0438 (\u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c). \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u044f \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e \u0438\u0445 \u043d\u0438\u0436\u0435. (<i>import<\/i> \u0438 <i>export<\/i> \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043c\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b)  <\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php protected function resourceAbilityMap() {     return [         'index' =&gt; 'viewAny',         'show' =&gt; 'view',         'create' =&gt; 'create',         'store' =&gt; 'create',         'edit' =&gt; 'update',         'update' =&gt; 'update',         'destroy' =&gt; 'delete',         'import' =&gt; 'import',         'export' =&gt; 'export',     ]; } <\/code><\/pre>\n<p>  <\/p>\n<p> \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u043a\u043b\u044e\u0447 \u044d\u0442\u043e \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0418 \u0437\u0434\u0435\u0441\u044c \u0443\u0436 \u043a\u0430\u043a \u043a\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0422\u0417. \u041c\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043e\u0442 \u0433\u0440\u0443\u043f\u043f\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 Spatie. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/github.com\/spatie\/laravel-permission\" rel=\"nofollow\">laravel-permission<\/a>. \u042f \u0434\u0443\u043c\u0430\u044e \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435 \u0432\u044b \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0443\u0436\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438. \u041e \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0435\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0438\u0436\u0435. \u0427\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u043d\u0430\u0442\u044c \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b <i>$user-&gt;can()<\/i> \u0438 <i>$user-&gt;hasRole()<\/i>, \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0442\u0440\u044d\u0439\u0442\u0430 <i>Spatie\\Permission\\Traits\\HasRoles<\/i>  <\/p>\n<p>  <\/p>\n<h5>\u041c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Models\\User)<\/h5>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Models;  use Illuminate\\Foundation\\Auth\\User as Authenticatable; use Illuminate\\Notifications\\Notifiable; use Spatie\\Permission\\Traits\\HasRoles;  class User extends Authenticatable {     use Notifiable;     use HasRoles;      \/** \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e *\/ } <\/code><\/pre>\n<p>  <\/p>\n<p> \u0421\u0442\u043e\u0438\u0442 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0432\u0435 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (<i>Admin<\/i> \u0438 <i>User<\/i>, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443) \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e \u0432\u0441\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0440\u0435\u0439\u0442 <i>HasRoles<\/i>, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0440\u043e\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a \u043d\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f.<br \/>   \u0412\u043e\u043e\u0440\u0443\u0436\u0438\u0432\u0448\u0438\u0441\u044c \u044d\u0442\u0438\u043c\u0438 \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438.  <\/p>\n<p>  <\/p>\n<h5>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 (ModelPolicy)<\/h5>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Policies;  use App\\Models\\User; use App\\Models\\Post; use Illuminate\\Auth\\Access\\HandlesAuthorization; use Illuminate\\Database\\Eloquent\\Model;  abstract class ModelPolicy {     use HandlesAuthorization;      abstract protected function getModelClass(): string;      public function viewAny(User $user)     {         return $user-&gt;can('view-any-' . $this-&gt;getModelClass());     }      public function view(User $user, Post $model)     {         return $user-&gt;can('view-' . $this-&gt;getModelClass());     }      public function create(User $user)     {         return $user-&gt;can('create-' . $this-&gt;getModelClass());     }      public function update(User $user, Post $model)     {         return $user-&gt;can('update-' . $this-&gt;getModelClass());     }      public function delete(User $user, Post $model)     {         return $user-&gt;can('delete-' . $this-&gt;getModelClass());     } } <\/code><\/pre>\n<p>  <\/p>\n<p> \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <i>$user-&gt;can(&#8216;ability&#8217;)<\/i> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0454\u0442\u0435 \u0432\u044b \u0435\u0433\u043e \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044e. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 &#8216;\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435&#8217;-&#8216;\u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430&#8217;, \u0433\u0434\u0435 \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u0438\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 (\u044d\u0442\u043e \u0432\u0438\u0434\u043d\u043e \u0432 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e \u043f\u043e\u0441\u0435\u0432\u0443 \u0434\u0430\u043d\u043d\u044b\u0445). \u0417\u0434\u0435\u0441\u044c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0434\u0435\u043b\u0435\u043d\u0438\u044f(SoftDelete). \u041d\u043e \u043e\u043d\u0430 \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443, \u0447\u0442\u043e \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b.<br \/>   \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u043c\u043e\u0434\u0435\u043b\u0438. \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e <i>Post<\/i> \u0438 \u043c\u0435\u0442\u043e\u0434 <i>getResourceName()<\/i> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.  <\/p>\n<p>  <\/p>\n<h5>\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 (PostPolicy)<\/h5>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Policies;  use App\\Models\\Post; use App\\Models\\User; use Illuminate\\Database\\Eloquent\\Model;  class PostPolicy extends ModelPolicy {     protected function getModelClass(): string     {         return Post::class;     }      public function import(User $user)     {         return $user-&gt;can('import-' . $this-&gt;getModelClass());     }      public function export(User $user, Post $model)     {         return $user-&gt;can('export-' . $this-&gt;getModelClass());     } } <\/code><\/pre>\n<p>  <\/p>\n<p> \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <i>import()<\/i> \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u0440\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u0438. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0443\u0447\u0435\u0441\u0442\u044c \u2014 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0430\u0434\u0430\u0442\u044c \u043f\u043e \u044f\u043a\u043e\u0431\u044b \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c. \u0418 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u043e\u0439, \u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0432\u0438\u043d\u043e\u0432\u043d\u0438\u043a\u0430. \u041f\u043e\u0442\u043e\u043c\u0443, \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0438\u0442\u0435\u0441\u044c \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443.  <\/p>\n<p>  <\/p>\n<p> \u0422\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430. \u041d\u043e \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.  <\/p>\n<p>  <\/p>\n<h2>\u0427\u0430\u0441\u0442\u044c 4. \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0435\u0432 \u043f\u0440\u0430\u0432 (Seeding)<\/h2>\n<p>  <\/p>\n<p> \u0414\u0430\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0441\u043a\u043e\u0440\u0435\u0435 \u0431\u043e\u043d\u0443\u0441\u043d\u0430\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u0441\u0432\u043e\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041d\u043e \u0432\u0441\u0435 \u0436\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0431\u044b\u043b \u0431\u044b \u043d\u0435\u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d \u0431\u0435\u0437 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438.<br \/>   \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c spatie\/laravel-permission, \u043f\u043e\u0442\u043e\u043c\u0443 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u0430. \u0412\u044b \u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0430\u0432 \u0432 \u0411\u0414.<br \/>   \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438:  <\/p>\n<p>  <\/p>\n<pre>     composer require spatie\/laravel-permission     php artisan vendor:publish --provider=&quot;Spatie\\Permission\\PermissionServiceProvider&quot; <\/pre>\n<p>  <\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u0435\u0432\u0430 (seeder)  <\/p>\n<p>  <\/p>\n<pre>     php artisan make:seeder PermissionsSeeder <\/pre>\n<p>  <\/p>\n<p> \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043a\u043b\u0430\u0441\u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 <i>run()<\/i> \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <i>database\/seeds\/DatabaseSeeder.php<\/i>. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 <i>PermissionsSeeder<\/i> \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0435\u0432\u0430 \u0431\u0430\u0437\u044b.  <\/p>\n<p>  <\/p>\n<h5>\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u0435\u0432\u0430 (DatabaseSeeder)<\/h5>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  use Illuminate\\Database\\Seeder;  class DatabaseSeeder extends Seeder {     public function run()     {          $this-&gt;call(PermissionsSeeder::class);     } } <\/code><\/pre>\n<p>  <\/p>\n<p> \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u2014 \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u0435\u0432\u0430 <i>PermissionsSeeder<\/i>. \u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u043f\u043a\u0443 <i>database\/data<\/i> \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u043d\u0435\u0439 php \u0444\u0430\u0439\u043b \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\u0430\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438. \u0424\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b:  <\/p>\n<p>  <\/p>\n<pre>     role =&gt; model =&gt; action <\/pre>\n<p>  <\/p>\n<h5>\u0424\u0430\u0439\u043b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0440\u043e\u043b\u044c\/\u043c\u043e\u0434\u0435\u043b\u044c\/\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 (permissions_roles.php)<\/h5>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  return [     'admin' =&gt; [         'App\\\\Models\\\\Post' =&gt; [             'view',             'view-any',             'create',             'update',             'delete',             'import',             'export',         ],     ],     'App\\\\Models\\\\Post' =&gt; [         'post' =&gt; [             'view',             'view-any',         ],     ], ]; <\/code><\/pre>\n<p>  <\/p>\n<p> \u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u0418, \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0430 \u043f\u043e\u0441\u043b\u0435 \u2014 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u044e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432.  <\/p>\n<p>  <\/p>\n<h5>\u041a\u043b\u0430\u0441\u0441 \u043f\u043e\u0441\u0435\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0438 (PermissionsSeeder)<\/h5>\n<pre><code class=\"php\">&lt;?php  use Illuminate\\Database\\Seeder; use Spatie\\Permission\\Models\\Permission; use Spatie\\Permission\\Models\\Role;  class PermissionsSeeder extends Seeder {     private $data = [];      public function run()     {         $this-&gt;loadData();         $this-&gt;seedRoles();     }      public function loadData(): void     {         $this-&gt;data = require_once database_path(&quot;data\/permissions_roles.php&quot;);     }      private function seedRoles(): void     {         Role::create(['name' =&gt; 'super-admin', 'guard_name' =&gt; 'api']);          foreach ($this-&gt;data as $roleName =&gt; $perms) {             $role = Role::create(['name' =&gt; $roleName, 'guard_name' =&gt; 'api']);             $this-&gt;seedRolePermissions($role, $perms);         }     }      private function seedRolePermissions(Role $role, array $modelPermissions): void     {         foreach ($modelPermissions as $model =&gt; $perms) {             $buildedPerms = collect($perms)                 -&gt;crossJoin($model)                 -&gt;map(function ($item) {                 $perm = implode('-', $item); \/\/view-post                 Permission::findOrCreate($perm, 'api');                  return $perm;             })-&gt;toArray();              $role-&gt;givePermissionTo($buildedPerms);         }     } } <\/code><\/pre>\n<p>  <\/p>\n<p> \u041a\u043b\u0430\u0441\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c, \u0438\u0437-\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041d\u043e \u0432 \u0434\u0430\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445, \u0431\u043e\u043b\u0435\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0447\u0442\u043e \u043f\u043e\u0432\u043b\u0435\u0447\u0435\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u0410 \u044d\u0442\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043d\u0435\u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e.<br \/>   \u0418\u0442\u0430\u043a, \u0438\u0434\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:  <\/p>\n<p>  <\/p>\n<ul>\n<li>\u041c\u0435\u0442\u043e\u0434 <i>run()<\/i> \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441.<\/li>\n<li> \u041c\u0435\u0442\u043e\u0434 <i>loadData()<\/i> \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043d\u0430\u0448\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441 \u043f\u0430\u043f\u043a\u0438 <i>database\/data<\/i> \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <i>$data<\/i>   <\/li>\n<li> \u041c\u0435\u0442\u043e\u0434 <i>seedRoles()<\/i> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0441\u0435\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u043e\u043b\u0435\u0439, \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 <i>$data<\/i>, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0441\u0435\u0432 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445. \u0420\u043e\u043b\u044c &#8216;super-admin&#8217; \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0438 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432, \u0442.\u043a. \u044d\u0442\u0430 \u0440\u043e\u043b\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e\u043b\u0438\u0442\u0438\u043a (\u0442\u0430\u043a \u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 <i>AuthServiceProvider<\/i>).   <\/li>\n<li> \u041c\u0435\u0442\u043e\u0434 <i>seedRolePermissions()<\/i> \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c, \u0438 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u00ab\u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u0442\u00bb \u0438\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0438\u043c\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044f \u0438\u043c\u0435\u043d\u0430 \u043f\u0440\u0430\u0432(permission). \u041f\u0440\u0430\u0432\u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u0411\u0414 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435\u043c \u0438\u0445 \u0440\u043e\u043b\u044f\u043c. \u0410 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438(\u043f\u0440\u0430\u0432\u0430) \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u043e\u0442 \u0440\u043e\u043b\u0438 \u043a \u0440\u043e\u043b\u0438 \u2014 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <i>findOrCreate()<\/i>, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <i>laravel-permissions<\/i>. \u042d\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e \u043f\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u043c \u043a \u0411\u0414, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0441\u0435\u0432 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0430\u0436\u0434\u044b.   <\/li>\n<\/ul>\n<p>  <\/p>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0441\u0435\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:  <\/p>\n<p>  <\/p>\n<pre>     php artisan migrate --seed <\/pre>\n<p>  <\/p>\n<p> <strong>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u0443\u044e \u0438 \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443.<\/strong> \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u043d\u043d\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430! \u0412\u0441\u0435 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u044d\u0442\u043e:  <\/p>\n<p>  <\/p>\n<ol>\n<li> \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c(Model).   <\/li>\n<li> \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440(Controller) \u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0442 <i>ModelController<\/i>.   <\/li>\n<li> \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443(Policy) \u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043e\u0442 <i>ModelPolicy<\/i>.   <\/li>\n<li> \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430.   <\/li>\n<\/ol>\n<p>  <\/p>\n<p> \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/497220\/\">(\u0441\u043c. \u0447\u0430\u0441\u0442\u044c 1)<\/a> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 (\u0441\u043c. \u0432\u044b\u0448\u0435).  <\/p>\n<p>  <\/p>\n<p> \u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u0432\u0441\u0435. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430. \u0410 \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u043d\u043a\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u0430\u0432 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u2014 <strong>\u043f\u0440\u0430\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\/\u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043c\u043e\u0434\u0435\u043b\u0438<\/strong> \u2014 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0447\u0430\u0441\u0442\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\/497834\/\"> https:\/\/habr.com\/ru\/post\/497834\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/497834\/\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435 \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0425\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435.<br \/>  \u042f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0441\u0432\u043e\u0439 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0432 Laravel. \u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043e \u0447\u0435\u043c \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/post\/497220\/\">\u041f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c<\/a>.  <\/p>\n<p>  <\/p>\n<p> \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0437\u0430\u0434\u0430\u0447\u0438: \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0433\u0438\u0431\u043a\u0443\u044e \u0438 \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0435\u0433\u043e \u0440\u043e\u043b\u0438.<br \/>   \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0441\u0432\u044f\u0437\u043a\u0438 \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430(Policy)&lt;=&gt;\u0428\u043b\u044e\u0437(Gate). \u0410 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0440\u0430\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<p>  <\/p>\n<p> \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0441\u0440\u0430\u0437\u0443 \u0443\u0442\u043e\u0447\u043d\u044e, \u0447\u0442\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443.  <\/p>\n<p>  <\/p>\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-302123","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302123","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=302123"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/302123\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}