{"id":370996,"date":"2024-05-21T04:38:13","date_gmt":"2024-05-21T04:38:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=370996"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=370996","title":{"rendered":"<span>\u041c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 API Resource \u0432 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 Laravel \u0435\u0441\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435 <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#main-content\" rel=\"noopener noreferrer nofollow\">API \u0440\u0435\u0441\u0443\u0440\u0441\u044b<\/a>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043b\u0435\u0433\u043a\u043e \u0438 \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044f\u043c\u0438? \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435!<\/p>\n<h2>\u0412\u0432\u043e\u0434\u043d\u0430\u044f<\/h2>\n<p>Laravel \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0440\u0430\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#main-content\" rel=\"noopener noreferrer nofollow\">API \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/a>. \u041f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u0442\u0432\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"id\": 123,     \"title\": \"Some title\"   } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"json\">{   \"data\": [     {       \"id\": 123,       \"title\": \"Some title\"     }   ] }<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"json\">{   \"data\": [     {       \"id\": 123,       \"title\": \"Some title\"     }   ],   \"links\": {     \"first\": \"http:\/\/localhost:8000\/?page=1\",     \"last\": \"http:\/\/localhost:8000\/?page=2\",     \"prev\": null,     \"next\": \"http:\/\/localhost:8000\/?page=2\"   },   \"meta\": {     \"current_page\": 1,     \"from\": 1,     \"last_page\": 2,     \"links\": [       {         \"url\": null,         \"label\": \"&amp;laquo; Previous\",         \"active\": false       },       {         \"url\": \"http:\/\/localhost:8000\/?page=1\",         \"label\": \"1\",         \"active\": true       },       {         \"url\": \"http:\/\/localhost:8000\/?page=2\",         \"label\": 2,         \"active\": false       },       {         \"url\": \"http:\/\/localhost:8000\/?page=2\",         \"label\": \"Next &amp;raquo;\",         \"active\": false       }     ],     \"path\": \"http:\/\/localhost:8000\/\",     \"per_page\": 2,     \"to\": 2,     \"total\": 3   } }<\/code><\/pre>\n<p>\u0418 \u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u0443\u0441\u0442\u0440\u0430\u0448\u0430\u044e\u0449\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 Laravel \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 API \u0438 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u043a \u043d\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439.<\/p>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 snake_case \u0432 camelCase<\/h2>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>camelCase<\/code>. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u044b \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043c \u0444\u0430\u043a\u0442.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043f\u0438\u0448\u0435\u043c \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0438 \u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f. \u041d\u043e \u043a\u0430\u043a \u0431\u044b\u0442\u044c \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u043c?<\/p>\n<p>\u041c\u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0442\u0440\u0438 \u043f\u0443\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b: \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u0439, \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438 \u043c\u0443\u0434\u0440\u0451\u043d\u044b\u0439.<\/p>\n<h4>\u041a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/h4>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0432\u0438\u0434\u0435\u043b, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u044e\u0434\u0435\u0439 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0432 \u0443\u0436\u0430\u0441. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e:<\/p>\n<pre><code class=\"php\">&lt;?php  public function index(Request $request) {     $items = Some::paginate();      $resource = SomeResource::collection($items);      $result = $this->convertToArray($resource->toArray($request));      return response()->json($result); }  protected function convertToArray(array $items): array {     $result = [];      foreach ($items as $key => $value) {         $newKey = Str::camel($key);          $result[$newKey] = is_array($value) ? $this->convertToArray($value) : $value;     }      return $result; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u0430\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0434\u043e &#8212; \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430 \u043b\u0438\u0446\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e\u043c\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0443.<\/p>\n<h4>\u0423\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439<\/h4>\n<p>Laravel \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u043f\u0443\u0442\u0451\u043c <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#customizing-the-pagination-information\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430<\/a> <code>paginationInformation<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0435\u0433\u043e \u0432 \u043e\u0431\u0449\u0438\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"php\">&lt;?php  public function paginationInformation($request, $paginated, $default) {     $default['links']['custom'] = 'https:\/\/example.com';       return $default; }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u044e. \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439?<\/p>\n<p>\u0412\u0441\u0451 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0434\u0451\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c. \u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0442\u0440\u0435\u0442\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 &#8212; \u043c\u0443\u0434\u0440\u0451\u043d\u044b\u0439.<\/p>\n<h4>\u041c\u0443\u0434\u0440\u0451\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/h4>\n<p>\u041c\u0443\u0434\u0440\u0451\u043d\u044b\u0439 \u043e\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0438\u043c\u0451\u043d \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 <code>camelCase<\/code> \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447.<\/p>\n<p>\u0422\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"json\">{   \"data\": [     {       \"id\": 123,       \"title\": \"Some title\"     }   ] }<\/code><\/pre>\n<p>\u0422\u043e \u043f\u043e \u043d\u043e\u0432\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"json\">{   \"data\": {    \"somes\": [       {         \"id\": 123,         \"title\": \"Some title\"       }     ]   } }<\/code><\/pre>\n<p>\u0413\u0434\u0435 <code>somes<\/code> &#8212; \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u044e\u0447\u0430 \u0438 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043e\u043d\u0430 \u0441\u0432\u043e\u044f.<\/p>\n<p>\u0421\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0437\u0430\u0447\u0435\u043c? \u041e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442 &#8212; \u043c\u0435\u0442\u0430-\u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0436\u0451\u0441\u0442\u043a\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u043e\u0442\u0432\u0435\u0442 \u043d\u0435\u0436\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0438\u0437 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0439 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432\u0430\u0442\u044c, \u0442.\u043a. \u0432\u043d\u0443\u0442\u0440\u0438 <code>data<\/code> \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441\u0432\u043e\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0447\u0435\u043c \u043c\u044b \u043d\u0438\u0436\u0435 \u0438 \u0437\u0430\u0439\u043c\u0451\u043c\u0441\u044f.<\/p>\n<h2>\u0411\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u043c \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u0440\u0435\u0441\u043f\u043e\u043d\u0441\u0430\u0445:<\/p>\n<ol>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0442\u0435\u043b\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>data<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u0442\u0435\u043b\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u043c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>data<\/code> \u043a\u043b\u044e\u0447\u0435, \u0438\u043c\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>users<\/code>, <code>posts<\/code>);<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435;<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u044b \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 <code>Y-m-d\\TH:i<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0438\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0432\u0438\u0434\u0443:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"id\": 123,     \"title\": \"Some title\",     \"createdAt\": \"2024-03-16T18:54\"   },   \"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   },   \"status\": \"OK\" }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e? \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 ? \u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043a\u043b\u044e\u0447\u0430 <code>status<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>OK<\/code>. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435\u0442 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>$additional<\/code> \u0440\u0435\u0441\u0443\u0440\u0441\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  public $additional = [     'status' => 'OK', ];<\/code><\/pre>\n<p>\u041d\u043e \u043e\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043b\u0438\u0431\u043e \u043f\u043b\u044f\u0441\u0430\u0442\u044c \u0441 \u0431\u0443\u0431\u043d\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0430. \u041d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0434\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441.<\/p>\n<h3>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c \u0447\u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>additional<\/code> \u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0432\u0435\u0442\u0435, \u0430 \u043d\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0438\u0445 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432 \u0442\u0440\u0435\u0439\u0442:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Concerns\\Resources;  trait HasAppends {     protected array $appends = [];      public function append(string $key, mixed $value): static     {         $this->appends[$key] = $value;          return $this;     }      public function setAppends(array $appends): static     {         $this->appends = array_merge($this->appends, $appends);          return $this;     }      protected function getAppend(string $key): mixed     {         return $this->appends[$key];     } } <\/code><\/pre>\n<h3>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442<\/h3>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442 \u0432 \u0440\u0435\u0441\u043f\u043e\u043d\u0441\u0430\u0445 &#8212; \u0440\u0443\u0447\u043d\u043e\u0435 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435. \u0421 \u0440\u0443\u0447\u043d\u044b\u043c \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u0442\u043d\u043e &#8212; \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u0430\u0442\u044b \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>->format('Y-m-d\\TH:i')<\/code>. \u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u0434\u0430\u0442 \u043c\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u0432\u043e\u0432\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0430\u0432\u0442\u043e\u0444\u043e\u0440\u043c\u0430\u0442.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u043d \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>jsonSerialize<\/code>:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Concerns\\Resources;  use Carbon\\Carbon;  trait HasJsonDates {     protected static ?string $dateFormat = null;      public function jsonSerialize(): array     {         return $this->resolveDates(             parent::jsonSerialize()         );     }      protected function resolveDates(array $items): array     {         foreach ($items as &amp;$item) {             if (is_array($item)) {                 $item = $this->resolveDates($item);                  continue;             }              if ($item instanceof Carbon) {                 $item = $item->format($this->dateFormat());             }         }          return $items;     }      protected function dateFormat(): string     {         return static::$dateFormat ?? config('resources.date.format');     } } <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0430 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439.<\/p>\n<h3>JSON \u0444\u043b\u0430\u0433\u0438<\/h3>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432 \u0442\u0440\u0435\u0439\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u043b\u0430\u0433\u043e\u0432 \u0434\u043b\u044f JSON \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Concerns\\Resources;  trait HasJsonOptions {     public function jsonOptions(): int     {         return JSON_UNESCAPED_SLASHES ^ JSON_UNESCAPED_UNICODE;     } } <\/code><\/pre>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442 \u0441 \u0446\u0435\u043b\u044c\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f &#171;\u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430&#187; ( <code>JSON_PRETTY_PRINT<\/code>).<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<h3>\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430<\/h3>\n<p>\u0417\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043b\u043e\u0439:<\/p>\n<ul>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 <code>status<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>OK<\/code> \u0432 \u043e\u0442\u0432\u0435\u0442\u0435;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442 \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e JSON \u0431\u0435\u0437 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u044b \u0432 \u044e\u043d\u0438\u043a\u043e\u0434 \u0438 \u043e\u0442\u043a\u0430\u0437 \u043e\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0435\u043d\u044c\u0448\u0435 \u0441\u043b\u043e\u0432, \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services\\Resources;  use App\\Concerns\\Resources\\HasJsonDates; use App\\Concerns\\Resources\\HasJsonOptions; 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->with, $with);     }      protected function resolveData(mixed $data): array     {         if ($data instanceof Collection) {             $data = $data->all();         }          return $this->resolveDates($data);     }      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>\u0414\u0443\u043c\u0430\u044e, \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435<\/p>\n<h3>\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/h3>\n<pre><code class=\"php\">&lt;?php  namespace App\\Http\\Resources;  use App\\Concerns\\Resources\\HasAppends; use App\\Services\\Resources\\ResourceResponseService; use Illuminate\\Contracts\\Pagination\\Paginator; use Illuminate\\Http\\JsonResponse; use Illuminate\\Http\\Request; use Illuminate\\Http\\Resources\\Json\\JsonResource; use Illuminate\\Support\\Collection as BaseCollection; use Illuminate\\Support\\Str;  final class Collection extends JsonResource {     use HasAppends;      public function __construct(         mixed $resource,         protected string $collects,         protected ?string $wrapKey,         protected ?string $dateFormat     ) {         parent::__construct($resource);     }      public function toResponse($request): JsonResponse     {         return (new ResourceResponseService(             $this,             $this->wrapper(),             $this->dateFormat         ))->toResponse($request);     }      public function toArray(Request $request): array     {         return $this->resource instanceof Paginator             ? $this->forwardAppends($this->resource->items())->toArray()             : $this->forwardAppends($this->resource)->toArray();     }      protected function forwardAppends(mixed $items): BaseCollection     {         return collect($items)->map(             fn (mixed $item) => (new $this->collects($item))->setAppends($this->appends)         );     }      protected function wrapper(): string     {         return $this->wrapKey ?? Str::of($this->collects)             ->afterLast('\\\\')             ->beforeLast('Resource')             ->snake()             ->plural()             ->toString();     } } <\/code><\/pre>\n<p>\u041f\u043e \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0443 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>setAppends<\/code> \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u0438 \u043f\u0440\u043e \u0432\u044b\u0437\u043e\u0432 \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041d\u043e \u0447\u0442\u043e \u0437\u0430 <code>wrapper<\/code>? \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d?<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>wrapper<\/code> \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 <code>$wrapKey<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0443 Laravel, \u043c\u044b \u0441\u0430\u043c\u0438 \u0435\u0433\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"495\" width=\"495\">\n<p align=\"left\"><strong>\u041a\u043b\u0430\u0441\u0441<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0418\u043c\u044f<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"495\" width=\"495\">\n<p align=\"left\"><code>App\\Http\\Resources\\PageResource<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>pages<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"495\" width=\"495\">\n<p align=\"left\"><code>App\\Http\\Resources\\PageItemResource<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>page_items<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"495\" width=\"495\">\n<p align=\"left\"><code>App\\Http\\Resources\\PageResourceCollection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>pages<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"495\" width=\"495\">\n<p align=\"left\"><code>App\\Http\\Resources\\PageItemResourceCollection<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>page_items<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041b\u0438\u0431\u043e \u043c\u043e\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>$dateFormat<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Http\\Resources;  use Illuminate\\Http\\Request;  \/** @mixin App\\Models\\Some *\/ class SomeResource extends Resource {     protected static ?string $wrapKey = 'qwerty';      protected static ?string $dateFormat = DATE_ATOM;      public function toArray(Request $request): array     {         return [             'id'        => $this->id,             'title'     => $this->title,             'createdAt' => $this->created_at,         ];     } }<\/code><\/pre>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u0447\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"json\">{   \"data\": {    \"qwerty\": [       {         \"id\": 123,         \"title\": \"Some title\",         \"createdAt\": \"2024-03-16T18:54:12+00:00\"       }     ]   },   \"status\": \"OK\" }<\/code><\/pre>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/h3>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0445\u0435\u043b\u043f\u0435\u0440\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 API \u0440\u0435\u0441\u0443\u0440\u0441\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Http\\Resources;  use App\\Concerns\\Resources\\HasAppends; use App\\Concerns\\Resources\\HasJsonDates; use App\\Services\\Resources\\ResourceResponseService; use Illuminate\\Http\\JsonResponse; use Illuminate\\Http\\Resources\\Json\\JsonResource;  abstract class Resource extends JsonResource {     use HasAppends;     use HasJsonDates;      protected static ?string $wrapKey = null;      public static function collection($resource): Collection     {         return new Collection($resource, static::class, static::$wrapKey, static::$dateFormat);     }      public function toResponse($request): JsonResponse     {         return (new ResourceResponseService(             $this,             null,             static::$dateFormat         ))->with($this->with)->toResponse($request);     } } <\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#generating-resource-collections\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439<\/a>. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0430\u0441\u0442\u044c\u0435!<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Http\\Resources;  use Illuminate\\Http\\Request;  \/** @mixin App\\Models\\Some *\/ class SomeResource extends Resource {     public function toArray(Request $request): array     {         return [             'id'    => $this->id,             'title' => $this->title,         ];     } }<\/code><\/pre>\n<h2>\u0428\u0430\u0431\u043b\u043e\u043d\u044b Laravel<\/h2>\n<h3>Laravel Stubs<\/h3>\n<p>\u041e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0439\u0442\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"bash\">php artisan stub:publish<\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b\u044b \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 <code>stubs<\/code> \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0444\u0430\u0439\u043b\u0435 <code>stubs\/resource.stub<\/code> \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439. \u041b\u0438\u0448\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<h3>Laravel Idea<\/h3>\n<p>\u042d\u0442\u043e <a href=\"https:\/\/laravel-idea.com\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u043f\u043b\u0430\u0433\u0438\u043d<\/a> \u0434\u043b\u044f PhpStorm \u0438 \u0441 \u043d\u0438\u043c \u0432\u0441\u0451 \u043f\u0440\u043e\u0449\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c60\/7bb\/fca\/c607bbfca85a09ef0f5e400bc4ae027d.png\" width=\"985\" height=\"763\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c60\/7bb\/fca\/c607bbfca85a09ef0f5e400bc4ae027d.png\"\/><\/figure>\n<h2>\u0421 \u043a\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f<\/h2>\n<p>\u0412 \u0445\u043e\u0434\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438, \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u044e\u0447 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043b\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u043a\u0430\u043a \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u043d\u0441\u0442\u0440:<\/p>\n<pre><code class=\"json\">{   \"data\": {    \"somes\": [       {         \"id\": 123,         \"title\": \"Some title\",         \"createdAt\": \"2024-03-16T18:54\",         \"category\": {           \"data\": {             \"id\": 1,             \"title\": \"Category name\"           },           \"pagination\": {             \"total\": 2,             \"perPage\": 2,             \"currentPage\": 1,             \"lastPage\": 2           },           \"status\": \"OK\"         }       }     ]   },   \"pagination\": {     \"total\": 2,     \"perPage\": 2,     \"currentPage\": 1,     \"lastPage\": 2   },   \"status\": \"OK\" }<\/code><\/pre>\n<p>\u0412\u0441\u0451 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043f\u043e-\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0440\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u0448\u0451\u043b \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0435\u0435.<\/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\/800715\/\"> https:\/\/habr.com\/ru\/articles\/800715\/<\/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 Laravel \u0435\u0441\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435 <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#main-content\" rel=\"noopener noreferrer nofollow\">API \u0440\u0435\u0441\u0443\u0440\u0441\u044b<\/a>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043b\u0435\u0433\u043a\u043e \u0438 \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044f\u043c\u0438? \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435!<\/p>\n<h2>\u0412\u0432\u043e\u0434\u043d\u0430\u044f<\/h2>\n<p>Laravel \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0440\u0430\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#main-content\" rel=\"noopener noreferrer nofollow\">API \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/a>. \u041f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u0442\u0432\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"id\": 123,     \"title\": \"Some title\"   } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"json\">{   \"data\": [     {       \"id\": 123,       \"title\": \"Some title\"     }   ] }<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"json\">{   \"data\": [     {       \"id\": 123,       \"title\": \"Some title\"     }   ],   \"links\": {     \"first\": \"http:\/\/localhost:8000\/?page=1\",     \"last\": \"http:\/\/localhost:8000\/?page=2\",     \"prev\": null,     \"next\": \"http:\/\/localhost:8000\/?page=2\"   },   \"meta\": {     \"current_page\": 1,     \"from\": 1,     \"last_page\": 2,     \"links\": [       {         \"url\": null,         \"label\": \"&amp;laquo; Previous\",         \"active\": false       },       {         \"url\": \"http:\/\/localhost:8000\/?page=1\",         \"label\": \"1\",         \"active\": true       },       {         \"url\": \"http:\/\/localhost:8000\/?page=2\",         \"label\": 2,         \"active\": false       },       {         \"url\": \"http:\/\/localhost:8000\/?page=2\",         \"label\": \"Next &amp;raquo;\",         \"active\": false       }     ],     \"path\": \"http:\/\/localhost:8000\/\",     \"per_page\": 2,     \"to\": 2,     \"total\": 3   } }<\/code><\/pre>\n<p>\u0418 \u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u0443\u0441\u0442\u0440\u0430\u0448\u0430\u044e\u0449\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 Laravel \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 API \u0438 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u043a \u043d\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439.<\/p>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 snake_case \u0432 camelCase<\/h2>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044f\u0442 \u043d\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>camelCase<\/code>. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u044b \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043c \u0444\u0430\u043a\u0442.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043f\u0438\u0448\u0435\u043c \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0438 \u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f. \u041d\u043e \u043a\u0430\u043a \u0431\u044b\u0442\u044c \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u043c?<\/p>\n<p>\u041c\u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0442\u0440\u0438 \u043f\u0443\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b: \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u0439, \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438 \u043c\u0443\u0434\u0440\u0451\u043d\u044b\u0439.<\/p>\n<h4>\u041a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/h4>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0432\u0438\u0434\u0435\u043b, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u044e\u0434\u0435\u0439 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0432 \u0443\u0436\u0430\u0441. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e:<\/p>\n<pre><code class=\"php\">&lt;?php  public function index(Request $request) {     $items = Some::paginate();      $resource = SomeResource::collection($items);      $result = $this->convertToArray($resource->toArray($request));      return response()->json($result); }  protected function convertToArray(array $items): array {     $result = [];      foreach ($items as $key => $value) {         $newKey = Str::camel($key);          $result[$newKey] = is_array($value) ? $this->convertToArray($value) : $value;     }      return $result; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u0430\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0434\u043e &#8212; \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430 \u043b\u0438\u0446\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e\u043c\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0443.<\/p>\n<h4>\u0423\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439<\/h4>\n<p>Laravel \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u043f\u0443\u0442\u0451\u043c <a href=\"https:\/\/laravel.com\/docs\/eloquent-resources#customizing-the-pagination-information\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430<\/a> <code>paginationInformation<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0435\u0433\u043e \u0432 \u043e\u0431\u0449\u0438\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"php\">&lt;?php  public function paginationInformation($request, $paginated, $default) {     $default['links']['custom'] = 'https:\/\/example.com';       return $default; }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0435\u043d\u0438\u044e. \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u0439?<\/p>\n<p>\u0412\u0441\u0451 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0434\u0451\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c. \u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0442\u0440\u0435\u0442\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 &#8212; \u043c\u0443\u0434\u0440\u0451\u043d\u044b\u0439.<\/p>\n<h4>\u041c\u0443\u0434\u0440\u0451\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/h4>\n<p>\u041c\u0443\u0434\u0440\u0451\u043d\u044b\u0439 \u043e\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0438\u043c\u0451\u043d \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 <code>camelCase<\/code> \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447.<\/p>\n<p>\u0422\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"json\">{   \"data\": [     {       \"id\": 123,       \"title\": \"Some title\"     }   ] }<\/code><\/pre>\n<p>\u0422\u043e \u043f\u043e \u043d\u043e\u0432\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"json\">{   \"data\": {    \"somes\": [       {         \"id\": 123,         \"title\": \"Some title\"       }     ]   } }<\/code><\/pre>\n<p>\u0413\u0434\u0435 <code>somes<\/code> &#8212; \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u044e\u0447\u0430 \u0438 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043e\u043d\u0430 \u0441\u0432\u043e\u044f.<\/p>\n<p>\u0421\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0437\u0430\u0447\u0435\u043c? \u041e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442 &#8212; \u043c\u0435\u0442\u0430-\u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0436\u0451\u0441\u0442\u043a\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u043e\u0442\u0432\u0435\u0442 \u043d\u0435\u0436\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0438\u0437 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u0435\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0439 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432\u0430\u0442\u044c, \u0442.\u043a. \u0432\u043d\u0443\u0442\u0440\u0438 <code>data<\/code> \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441\u0432\u043e\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0447\u0435\u043c \u043c\u044b \u043d\u0438\u0436\u0435 \u0438 \u0437\u0430\u0439\u043c\u0451\u043c\u0441\u044f.<\/p>\n<h2>\u0411\u0438\u0437\u043d\u0435\u0441-\u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u043c \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u0440\u0435\u0441\u043f\u043e\u043d\u0441\u0430\u0445:<\/p>\n<ol>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0442\u0435\u043b\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>data<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p>\u0442\u0435\u043b\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u043c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>data<\/code> \u043a\u043b\u044e\u0447\u0435, \u0438\u043c\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>users<\/code>, <code>posts<\/code>);<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0430\u0433\u0438\u043d\u0430\u0442\u043e\u0440\u0430 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435;<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u044b \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 <code>Y-m-d\\TH:i<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0438\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0432\u0438\u0434\u0443:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"id\": 123,     \"title\": \"Some title\",     \"createdAt\": \"2024-03-16T18:54\"   },   \"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   },   \"status\": \"OK\" }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e? \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 ? \u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043a\u043b\u044e\u0447\u0430 <code>status<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>OK<\/code>. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435\u0442 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>$additional<\/code> \u0440\u0435\u0441\u0443\u0440\u0441\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  public $additional = [     'status' => 'OK', ];<\/code><\/pre>\n<p>\u041d\u043e \u043e\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043b\u0438\u0431\u043e \u043f\u043b\u044f\u0441\u0430\u0442\u044c \u0441 \u0431\u0443\u0431\u043d\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0430. \u041d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0434\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441.<\/p>\n<h3>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c \u0447\u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <code>additional<\/code> \u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0432\u0435\u0442\u0435, \u0430 \u043d\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0438\u0445 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432 \u0442\u0440\u0435\u0439\u0442:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Concerns\\Resources;  trait HasAppends {     protected array $appends = [];      public function append(string $key, mixed $value): static     {         $this->appends[$key] = $value;          return $this;     }      public function setAppends(array $appends): static     {         $this->appends = array_merge($this->appends, $appends);          return $this;     }      protected function getAppend(string $key): mixed     {         return $this->appends[$key];     } } <\/code><\/pre>\n<h3>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442<\/h3>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442 \u0432 \u0440\u0435\u0441\u043f\u043e\u043d\u0441\u0430\u0445 &#8212; \u0440\u0443\u0447\u043d\u043e\u0435 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435. \u0421 \u0440\u0443\u0447\u043d\u044b\u043c \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u0442\u043d\u043e &#8212; \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u0430\u0442\u044b \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>->format('Y-m-d\\TH:i')<\/code>. \u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u0434\u0430\u0442 \u043c\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u0432\u043e\u0432\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0430\u0432\u0442\u043e\u0444\u043e\u0440\u043c\u0430\u0442.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u043d \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>jsonSerialize<\/code>:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Concerns\\Resources;  use Carbon\\Carbon;  trait HasJsonDates {     protected static ?string $dateFormat = null;      public function jsonSerialize(): array     {         return $this->resolveDates(             parent::jsonSerialize()         );     }      protected function resolveDates(array $items): array     {         foreach ($items as &amp;$item) {             if (is_array($item)) {                 $item = $this->resolveDates($item);                  continue;             }              if ($item instanceof Carbon) {                 $item = $item->format($this->dateFormat());             }         }          return $items;     }      protected function dateFormat(): string     {         return static::$dateFormat ?? config('resources.date.format');     } } <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0430 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439.<\/p>\n<h3>JSON \u0444\u043b\u0430\u0433\u0438<\/h3>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432 \u0442\u0440\u0435\u0439\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u043b\u0430\u0433\u043e\u0432 \u0434\u043b\u044f JSON \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Concerns\\Resources;  trait HasJsonOptions {     public function jsonOptions(): int     {         return JSON_UNESCAPED_SLASHES ^ JSON_UNESCAPED_UNICODE;     } } <\/code><\/pre>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442 \u0441 \u0446\u0435\u043b\u044c\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f &#171;\u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430&#187; ( <code>JSON_PRETTY_PRINT<\/code>).<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<h3>\u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430<\/h3>\n<p>\u0417\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043b\u043e\u0439:<\/p>\n<ul>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 <code>status<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>OK<\/code> \u0432 \u043e\u0442\u0432\u0435\u0442\u0435;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442 \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e JSON \u0431\u0435\u0437 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u044b \u0432 \u044e\u043d\u0438\u043a\u043e\u0434 \u0438 \u043e\u0442\u043a\u0430\u0437 \u043e\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0435\u043d\u044c\u0448\u0435 \u0441\u043b\u043e\u0432, \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u0430:<\/p>\n<pre><code class=\"php\">&lt;?php  namespace App\\Services\\Resources;  use App\\Concerns\\Resources\\HasJsonDates; use App\\Concerns\\Resources\\HasJsonOptions; 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;  <\/code><\/pre>\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-370996","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370996","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=370996"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370996\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}