{"id":370998,"date":"2024-05-21T04:38:18","date_gmt":"2024-05-21T04:38:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=370998"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=370998","title":{"rendered":"<span>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445 Laravel<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/articles\/800715\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 API \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0432 Laravel \u0431\u044b\u043b\u0430 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u0430 \u0442\u0435\u043c\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a API \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u00a0\u044d\u0442\u043e\u0439 \u043c\u044b \u043f\u043e\u0439\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0432\u0432\u0435\u0434\u0451\u043c \u043d\u043e\u0432\u0443\u044e \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u00a0\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00ab\u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438\u00bb. \u0418\u0445 \u0441\u0443\u0442\u044c \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u00a0\u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043d\u0430\u00a0\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u00a0\u043a\u0430\u043a\u0438\u0445\u2011\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445.<\/p>\n<h2>\u0411\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u041f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e &#171;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c&#187; \u044d\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0446\u0435\u043b\u044c\u044e \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a API.<\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"id\": 123,     \"title\": \"Some title\"   },   \"notifications\": [     {       \"title\": \"\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b\",       \"text\": \"\u0417\u0430\u043f\u0438\u0441\u044c #123 \\\"Some title\\\" \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0430.\",       \"type\": \"OK\"     },     {       \"title\": \"\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438\",       \"text\": \"\u0417\u0430\u043f\u0438\u0441\u044c #456 \\\"Another title\\\" \u0431\u044b\u043b\u0430 \u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0430.\",       \"type\": \"WARNING\"     },     {       \"title\": \"\u0423\u043f\u0441! \u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a!\",       \"text\": \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \\\"&lt;name>\\\".\",       \"type\": \"ERROR\"     }   ],   \"status\": \"OK\" }<\/code><\/pre>\n<h2>\u041c\u044b\u0441\u043b\u0438<\/h2>\n<p>\u041d\u0430 \u0432\u0438\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432\u044b\u0432\u043e\u0434 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>additional<\/code> \u0434\u0430 \u0438 \u0432\u0441\u0451. \u041d\u043e \u043d\u0435\u0442. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0447\u0442\u043e \u043c\u044b &#8212; \u043b\u0435\u043d\u0438\u0432\u044b\u0435) \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u043f\u0440\u0435\u0434\u044c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438 \u0438 &#171;\u043e\u043d\u043e \u0441\u0430\u043c\u043e&#187; \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0442\u043e \u043d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043b\u0438\u0448\u044c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 &#8212; \u043f\u0440\u044f\u043c\u043e\u0439 \u0438 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439.<\/p>\n<p>\u0412 &#171;\u043f\u0440\u044f\u043c\u043e\u043c&#187; \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043e\u0442\u0434\u0430\u0451\u043c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c DTO \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041c\u0438\u043d\u0443\u0441 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0443 DTO \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0437\u0434\u0435 \u0438 \u0432\u0441\u044f, \u043b\u043e\u043c\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0436\u0451\u0441\u0442\u043a\u043e \u0437\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435 DTO, \u0432\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0435\u0449\u0451 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u0417\u0430\u0447\u0435\u043c? \u0412\u043e\u0442 \u0438 \u044f \u0433\u043e\u0432\u043e\u0440\u044e \u0447\u0442\u043e \u043d\u0435 \u0437\u0430 \u0447\u0435\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0439\u0434\u0451\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0443\u0442\u0451\u043c \u0438\u0431\u043e \u043d\u0430\u043c &#8212; \u043b\u0435\u043d\u044c (\u043f\u043e\u043c\u043d\u0438\u043c, \u0434\u0430?).<\/p>\n<p>\u041c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Singleton \u0432 Laravel \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u0438 \u0434\u043e. \u041c\u0438\u043d\u0443\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 Laravel Octane \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043c\u0435\u043d\u044f \u043e\u043a\u0442\u0430\u043d \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0430\u0447\u0430\u0432\u0448\u0438\u0441\u044c ?<\/p>\n<h2>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e! \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. \u041f\u0440\u0438 \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u0443\u0434\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0451 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0417\u0432\u0443\u0447\u0438\u0442 \u043b\u0435\u0433\u043a\u043e, \u043d\u043e \u043a\u0430\u043a \u043f\u043e\u0439\u0434\u0451\u0442 \u043d\u0430 \u0434\u0435\u043b\u0435 &#8212; \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u043f\u043e \u0445\u043e\u0434\u0443 \u0434\u0435\u043b\u0430.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c Enum \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Enums;  enum NotificationTypeEnum: string {     case Ok      = 'OK';     case Warning = 'WARNING';     case Error   = 'ERROR'; }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 DTO \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Data;  use App\\Enums\\NotificationTypeEnum;  class NotificationData {     public function __construct(         public NotificationTypeEnum $type,         public ?string $title,         public ?string $text     ) {} }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442 \u043d\u0430\u043c \u0435\u0434\u0438\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0418 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 API \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Http\\Resources;  use App\\Dto\\NotificationData; use App\\Enums\\NotificationTypeEnum; use App\\Http\\Resources\\Resource; use Illuminate\\Http\\Request;  \/** @mixin NotificationData *\/ class NotificationResource extends Resource {     public function toArray(Request $request): array     {         return [             'title' => $this->title(),             'text'  => $this->text,             'type'  => $this->type->value,         ];     }      protected function title(): string     {         return $this->title ?? match ($this->type) {             NotificationTypeEnum::Success => __('The changes have been successfully saved'),             NotificationTypeEnum::Warning => __('Information display has been changed'),             NotificationTypeEnum::Error   => __('Whoops! Something wrong'),         };     } } <\/code><\/pre>\n<p>\u0418\u0434\u0435\u044f \u0442\u0430\u043a\u0430\u044f, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e, \u0438\u043d\u0430\u0447\u0435 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439.<\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<h2>\u0421\u0435\u0440\u0432\u0438\u0441<\/h2>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0445\u0435\u043b\u043f\u0435\u0440 <code>app()<\/code>, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434, \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public static function push(NotificationTypeEnum $type, ?string $text, ?string $title = null): void     {         app(static::class)->add($type, $title, $text);     }      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u0412\u043d\u043e\u0432\u044c \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0447\u0442\u043e \u043c\u044b \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u043e\u0439 \u0441\u0435\u0431\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439: <code>success<\/code>, <code>warning<\/code> \u0438 <code>error<\/code>:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use App\\Enums\\NotificationTypeEnum; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public static function success(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Success, $text, $title);     }      public static function warning(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Warning, $text, $title);     }      public static function error(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Error, $text, $title);     }      protected static function push(NotificationTypeEnum $type, ?string $text, ?string $title = null): void     {         app(static::class)->add($type, $title, $text);     }      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c &#8212; \u0432\u044b\u0432\u043e\u0434 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0447\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0447\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443 \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0432\u043e\u0439, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>null<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0440\u043e\u0449\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0427\u0442\u043e \u0436, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use App\\Enums\\NotificationTypeEnum; use App\\Http\\Resources\\NotificationResource; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public static function success(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Success, $text, $title);     }      public static function warning(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Warning, $text, $title);     }      public static function error(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Error, $text, $title);     }      protected static function push(NotificationTypeEnum $type, ?string $text, ?string $title = null): void     {         app(static::class)->add($type, $title, $text);     }      public static function toResource(): ?Collection     {         if ($items = app(static::class)->toArray()) {             return collect($items)->mapInto(NotificationResource::class);         }          return null;     }      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>toResource<\/code> \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u043e\u0431\u0440\u043e\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441 \u0446\u0435\u043b\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0443\u0431\u043b\u044f\u0436\u0430 \u043a\u043e\u0434\u0430 \u0441\u043d\u0430\u0440\u0443\u0436\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0436\u0451\u0441\u0442\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0432 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f\u0445 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c \u0438\u043b\u0438 \u043f\u0440\u0438 <a href=\"https:\/\/laravel.com\/docs\/events#generating-events-and-listeners\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u0438 \u044d\u0432\u0435\u043d\u0442\u043e\u0432<\/a> \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0412 \u044d\u0442\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u0442.<\/p>\n<pre><code class=\"php\">&lt;?php  use App\\Services\\NotificationService;  NotificationService::success('\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21161.'); NotificationService::success('\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21162.', '\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c');  NotificationService::warning('\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21163.'); NotificationService::warning('\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21164.', '\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c');  NotificationService::error('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Foo.'); NotificationService::error('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Bar.', '\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445');<\/code><\/pre>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h2>\n<p>\u041d\u041e \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u041d\u0443\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0438\u043c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441-\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 <code>AppServiceProvider<\/code>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0432 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>register<\/code>:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Providers;  use App\\Services\\NotificationService; use Illuminate\\Support\\ServiceProvider;  class AppServiceProvider extends ServiceProvider {     public function register(): void     {         $this->notifications();     }      protected function notifications(): void     {         $this->app->singleton(NotificationService::class, fn() => new NotificationService());     } } <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0447\u0442\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441.<\/p>\n<h2>API Resource<\/h2>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u043a\u0430\u043a \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/800715\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 <code>ResourceResponseService<\/code>? \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services\\Resources;  use App\\Concerns\\Resources\\HasJsonDates; use App\\Concerns\\Resources\\HasJsonOptions; use App\\Services\\NotificationService; use Illuminate\\Contracts\\Pagination\\LengthAwarePaginator; use Illuminate\\Contracts\\Support\\Responsable; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Http\\JsonResponse; use Illuminate\\Http\\Resources\\Json\\JsonResource; use Illuminate\\Http\\Resources\\MissingValue; use Illuminate\\Support\\Arr; use Illuminate\\Support\\Collection; use Symfony\\Component\\HttpFoundation\\Response;  class ResourceResponseService implements Responsable {     use HasJsonDates;     use HasJsonOptions;      protected array $with = [         'status' => 'OK',     ];      public function __construct(         protected JsonResource $resource,         protected ?string $wrap,         ?string $dateFormat     ) {         static::$dateFormat = $dateFormat;     }      public function with(array $data): static     {         $this->with = array_merge($this->with, $data);          return $this;     }      public function toResponse($request): JsonResponse     {         return tap(             response()->json(                 data: $this->wrap(                     $this->resource->resolve($request),                     $this->resource->with($request),                     $this->resource->additional                 ),                 status: $this->status(),                 options: $this->jsonOptions()             ),             function ($response) use ($request) {                 $response->original = $this->resource->resource;                  $this->resource->withResponse($request, $response);             }         );     }      protected function wrap(mixed $data, array $with, array $additional): array     {         Arr::set($result, $this->wrapper(), $this->resolveData($data));          return array_merge($result, $additional, $this->withPagination(), $this->withNotifications(), $this->with, $with);     }      protected function resolveData(mixed $data): array     {         if ($data instanceof Collection) {             $data = $data->all();         }          return $this->resolveDates($data);     }      protected function withNotifications(): array     {         if ($items = NotificationService::toResource()) {             return ['notifications' => $items];         }          return [];     }      protected function wrapper(): string     {         return 'data' . ($this->wrap ? '.' . $this->wrap : '');     }      protected function status(): int     {         if ($this->resource->resource instanceof Model &amp;&amp; $this->resource->resource->wasRecentlyCreated) {             return Response::HTTP_CREATED;         }          return Response::HTTP_OK;     }      protected function isPagination(): bool     {         return $this->resource->resource instanceof LengthAwarePaginator;     }      protected function withPagination(): array     {         return $this->isPagination() ? $this->paginationInformation($this->resource->resource) : [];     }      protected function paginationInformation(LengthAwarePaginator $paginated): array     {         return [             'pagination' => [                 'total' => $paginated->total(),                 'perPage' => $paginated->perPage(),                 'currentPage' => $paginated->currentPage(),                 'lastPage' => $paginated->lastPage(),             ],         ];     } }<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0442\u0440\u043e\u043a\u0435 <code>78<\/code> \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439, \u0430 \u043d\u0430 <code>66<\/code>-\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0438\u0434\u044b \u043e\u0442\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0434\u043b\u044f \u0438\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430:<\/p>\n<pre><code class=\"json\">{     \"data\": {         \"id\": 123,         \"title\": \"Some title\",         \"createdAt\": \"2024-03-16T18:54\"     },     \"notifications\": [         {             \"title\": \"The changes have been successfully saved\",             \"text\": \"\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21161.\",             \"type\": \"SUCCESS\"         },         {             \"title\": \"\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c\",             \"text\": \"\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21162.\",             \"type\": \"SUCCESS\"         },         {             \"title\": \"Information display has been changed\",             \"text\": \"\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21163.\",             \"type\": \"WARNING\"         },         {             \"title\": \"\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c\",             \"text\": \"\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21164.\",             \"type\": \"WARNING\"         },         {             \"title\": \"Whoops! Something wrong\",             \"text\": \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Foo.\",             \"type\": \"ERROR\"         },         {             \"title\": \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445\",             \"text\": \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Bar.\",             \"type\": \"ERROR\"         }     ],     \"status\": \"OK\" }<\/code><\/pre>\n<pre><code class=\"json\">{     \"data\": {         \"somes\": [             {                 \"id\": 123,                 \"title\": \"Some title\",                 \"createdAt\": \"2024-03-16T18:54\",                 \"category\": {                     \"id\": 1,                     \"title\": \"Category name\"                 }             },             {                 \"id\": 456,                 \"title\": \"Another title\",                 \"createdAt\": \"2024-03-16T18:55\",                 \"category\": null             }         ]     },     \"pagination\": {         \"total\": 2,         \"perPage\": 2,         \"currentPage\": 1,         \"lastPage\": 2     },     \"notifications\": [         {             \"title\": \"The changes have been successfully saved\",             \"text\": \"\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21161.\",             \"type\": \"SUCCESS\"         },         {             \"title\": \"\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c\",             \"text\": \"\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21162.\",             \"type\": \"SUCCESS\"         },         {             \"title\": \"Information display has been changed\",             \"text\": \"\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21163.\",             \"type\": \"WARNING\"         },         {             \"title\": \"\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c\",             \"text\": \"\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21164.\",             \"type\": \"WARNING\"         },         {             \"title\": \"Whoops! Something wrong\",             \"text\": \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Foo.\",             \"type\": \"ERROR\"         },         {             \"title\": \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445\",             \"text\": \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Bar.\",             \"type\": \"ERROR\"         }     ],     \"status\": \"OK\" }<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"json\">{     \"data\": {         \"id\": 123,         \"title\": \"Some title\",         \"createdAt\": \"2024-03-16T18:54\"     },     \"status\": \"OK\" }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451. \u041f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043b\u044e\u0431\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\/\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/800723\/\"> https:\/\/habr.com\/ru\/articles\/800723\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/articles\/800715\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 API \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0432 Laravel \u0431\u044b\u043b\u0430 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u0430 \u0442\u0435\u043c\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a API \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u00a0\u044d\u0442\u043e\u0439 \u043c\u044b \u043f\u043e\u0439\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0432\u0432\u0435\u0434\u0451\u043c \u043d\u043e\u0432\u0443\u044e \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u00a0\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00ab\u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438\u00bb. \u0418\u0445 \u0441\u0443\u0442\u044c \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u00a0\u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043d\u0430\u00a0\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u00a0\u043a\u0430\u043a\u0438\u0445\u2011\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445.<\/p>\n<h2>\u0411\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u041f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e &#171;\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c&#187; \u044d\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0446\u0435\u043b\u044c\u044e \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a API.<\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"id\": 123,     \"title\": \"Some title\"   },   \"notifications\": [     {       \"title\": \"\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b\",       \"text\": \"\u0417\u0430\u043f\u0438\u0441\u044c #123 \\\"Some title\\\" \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0430.\",       \"type\": \"OK\"     },     {       \"title\": \"\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438\",       \"text\": \"\u0417\u0430\u043f\u0438\u0441\u044c #456 \\\"Another title\\\" \u0431\u044b\u043b\u0430 \u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0430.\",       \"type\": \"WARNING\"     },     {       \"title\": \"\u0423\u043f\u0441! \u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a!\",       \"text\": \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \\\"&lt;name>\\\".\",       \"type\": \"ERROR\"     }   ],   \"status\": \"OK\" }<\/code><\/pre>\n<h2>\u041c\u044b\u0441\u043b\u0438<\/h2>\n<p>\u041d\u0430 \u0432\u0438\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432\u044b\u0432\u043e\u0434 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>additional<\/code> \u0434\u0430 \u0438 \u0432\u0441\u0451. \u041d\u043e \u043d\u0435\u0442. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0447\u0442\u043e \u043c\u044b &#8212; \u043b\u0435\u043d\u0438\u0432\u044b\u0435) \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u043f\u0440\u0435\u0434\u044c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438 \u0438 &#171;\u043e\u043d\u043e \u0441\u0430\u043c\u043e&#187; \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0442\u043e \u043d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043b\u0438\u0448\u044c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 &#8212; \u043f\u0440\u044f\u043c\u043e\u0439 \u0438 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439.<\/p>\n<p>\u0412 &#171;\u043f\u0440\u044f\u043c\u043e\u043c&#187; \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043e\u0442\u0434\u0430\u0451\u043c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c DTO \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041c\u0438\u043d\u0443\u0441 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0443 DTO \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0437\u0434\u0435 \u0438 \u0432\u0441\u044f, \u043b\u043e\u043c\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0436\u0451\u0441\u0442\u043a\u043e \u0437\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435 DTO, \u0432\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0435\u0449\u0451 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u0417\u0430\u0447\u0435\u043c? \u0412\u043e\u0442 \u0438 \u044f \u0433\u043e\u0432\u043e\u0440\u044e \u0447\u0442\u043e \u043d\u0435 \u0437\u0430 \u0447\u0435\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0439\u0434\u0451\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0443\u0442\u0451\u043c \u0438\u0431\u043e \u043d\u0430\u043c &#8212; \u043b\u0435\u043d\u044c (\u043f\u043e\u043c\u043d\u0438\u043c, \u0434\u0430?).<\/p>\n<p>\u041c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Singleton \u0432 Laravel \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u0438 \u0434\u043e. \u041c\u0438\u043d\u0443\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 Laravel Octane \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043c\u0435\u043d\u044f \u043e\u043a\u0442\u0430\u043d \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0430\u0447\u0430\u0432\u0448\u0438\u0441\u044c ?<\/p>\n<h2>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438? \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e! \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. \u041f\u0440\u0438 \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u0443\u0434\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0451 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0417\u0432\u0443\u0447\u0438\u0442 \u043b\u0435\u0433\u043a\u043e, \u043d\u043e \u043a\u0430\u043a \u043f\u043e\u0439\u0434\u0451\u0442 \u043d\u0430 \u0434\u0435\u043b\u0435 &#8212; \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u043f\u043e \u0445\u043e\u0434\u0443 \u0434\u0435\u043b\u0430.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c Enum \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Enums;  enum NotificationTypeEnum: string {     case Ok      = 'OK';     case Warning = 'WARNING';     case Error   = 'ERROR'; }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 DTO \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Data;  use App\\Enums\\NotificationTypeEnum;  class NotificationData {     public function __construct(         public NotificationTypeEnum $type,         public ?string $title,         public ?string $text     ) {} }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442 \u043d\u0430\u043c \u0435\u0434\u0438\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0418 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 API \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Http\\Resources;  use App\\Dto\\NotificationData; use App\\Enums\\NotificationTypeEnum; use App\\Http\\Resources\\Resource; use Illuminate\\Http\\Request;  \/** @mixin NotificationData *\/ class NotificationResource extends Resource {     public function toArray(Request $request): array     {         return [             'title' => $this->title(),             'text'  => $this->text,             'type'  => $this->type->value,         ];     }      protected function title(): string     {         return $this->title ?? match ($this->type) {             NotificationTypeEnum::Success => __('The changes have been successfully saved'),             NotificationTypeEnum::Warning => __('Information display has been changed'),             NotificationTypeEnum::Error   => __('Whoops! Something wrong'),         };     } } <\/code><\/pre>\n<p>\u0418\u0434\u0435\u044f \u0442\u0430\u043a\u0430\u044f, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e, \u0438\u043d\u0430\u0447\u0435 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439.<\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<h2>\u0421\u0435\u0440\u0432\u0438\u0441<\/h2>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0445\u0435\u043b\u043f\u0435\u0440 <code>app()<\/code>, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434, \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public static function push(NotificationTypeEnum $type, ?string $text, ?string $title = null): void     {         app(static::class)->add($type, $title, $text);     }      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u0412\u043d\u043e\u0432\u044c \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0447\u0442\u043e \u043c\u044b \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u043e\u0439 \u0441\u0435\u0431\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439: <code>success<\/code>, <code>warning<\/code> \u0438 <code>error<\/code>:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use App\\Enums\\NotificationTypeEnum; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public static function success(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Success, $text, $title);     }      public static function warning(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Warning, $text, $title);     }      public static function error(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Error, $text, $title);     }      protected static function push(NotificationTypeEnum $type, ?string $text, ?string $title = null): void     {         app(static::class)->add($type, $title, $text);     }      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c &#8212; \u0432\u044b\u0432\u043e\u0434 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0447\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0447\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443 \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0432\u043e\u0439, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>null<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0440\u043e\u0449\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0427\u0442\u043e \u0436, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services;  use App\\Data\\NotificationData; use App\\Enums\\NotificationTypeEnum; use App\\Http\\Resources\\NotificationResource; use Illuminate\\Contracts\\Support\\Arrayable;  class NotificationService implements Arrayable {     protected array $items = [];      public static function success(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Success, $text, $title);     }      public static function warning(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Warning, $text, $title);     }      public static function error(?string $text = null, ?string $title = null): void     {         static::push(NotificationTypeEnum::Error, $text, $title);     }      protected static function push(NotificationTypeEnum $type, ?string $text, ?string $title = null): void     {         app(static::class)->add($type, $title, $text);     }      public static function toResource(): ?Collection     {         if ($items = app(static::class)->toArray()) {             return collect($items)->mapInto(NotificationResource::class);         }          return null;     }      public function toArray(): array     {         return $this->items;     }      protected function add(NotificationTypeEnum $type, ?string $title, ?string $text): void     {         $this->items[] = new NotificationData($type, $title, $text);     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>toResource<\/code> \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u043e\u0431\u0440\u043e\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441 \u0446\u0435\u043b\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0443\u0431\u043b\u044f\u0436\u0430 \u043a\u043e\u0434\u0430 \u0441\u043d\u0430\u0440\u0443\u0436\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0436\u0451\u0441\u0442\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0432 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f\u0445 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c \u0438\u043b\u0438 \u043f\u0440\u0438 <a href=\"https:\/\/laravel.com\/docs\/events#generating-events-and-listeners\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u0438 \u044d\u0432\u0435\u043d\u0442\u043e\u0432<\/a> \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0412 \u044d\u0442\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0435\u0442.<\/p>\n<pre><code class=\"php\">&lt;?php  use App\\Services\\NotificationService;  NotificationService::success('\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21161.'); NotificationService::success('\u041e\u0431\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u21162.', '\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c');  NotificationService::warning('\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21163.'); NotificationService::warning('\u041d\u0435 \u043c\u043e\u0433\u0443 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u21164.', '\u0427\u0442\u043e-\u0442\u043e \u043f\u0438\u0448\u0435\u043c');  NotificationService::error('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Foo.'); NotificationService::error('\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 Bar.', '\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445');<\/code><\/pre>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h2>\n<p>\u041d\u041e \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u041d\u0443\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0438\u043c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441-\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 <code>AppServiceProvider<\/code>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0432 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 <code>register<\/code>:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Providers;  use App\\Services\\NotificationService; use Illuminate\\Support\\ServiceProvider;  class AppServiceProvider extends ServiceProvider {     public function register(): void     {         $this->notifications();     }      protected function notifications(): void     {         $this->app->singleton(NotificationService::class, fn() => new NotificationService());     } } <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0447\u0442\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e<\/p>\n<\/div>\n<\/div>\n<\/div>\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-370998","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370998","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=370998"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370998\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}