{"id":1316,"date":"2023-11-18T11:28:43","date_gmt":"2023-11-18T11:28:43","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1316"},"modified":"2023-11-29T11:37:50","modified_gmt":"2023-11-29T11:37:50","slug":"error-http-500-internal-serverilluminatehttpresourcesjsonresource-not-found","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/error-http-500-internal-serverilluminatehttpresourcesjsonresource-not-found\/","title":{"rendered":"Error: HTTP 500\u00a0Internal Server&#8221;Illuminate\\Http\\Resources\\Json\\Resource&#8221; not found"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"371\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38-1024x371.png\" alt=\"\" class=\"wp-image-1317\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38-1024x371.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38-300x109.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38-768x278.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38-1536x556.png 1536w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38-850x308.png 850w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-38.png 1785w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The error message indicates that the class &#8220;Illuminate\\Http\\Resources\\Json\\Resource&#8221; cannot be found. This typically occurs when attempting to use the Resource class in a resource file. In the provided code snippet, the class &#8220;Country&#8221; extends &#8220;Resource,&#8221; triggering the error.<\/p>\n\n\n\n<p>Error :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>namespace App\\Http\\Resources;\r\n\r\nuse Illuminate\\Http\\Resources\\Json\\Resource;\r\n\r\nclass Country extends Resource\r\n{\r\n    \/\/ Class implementation\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>Solution: The root cause of this error lies in the changes made to Laravel&#8217;s resource classes in the latest versions. To resolve the issue, you need to update your code to reflect the changes in the Laravel framework. Specifically, you should replace the old &#8220;Resource&#8221; class with the new &#8220;JsonResource&#8221; class.<\/p>\n\n\n\n<p>Updated Solution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nnamespace App\\Http\\Resources;\r\n\r\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\r\n\r\nclass Country extends JsonResource\r\n{\r\n    \/\/ Class implementation\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>In the updated solution, we replace the old &#8220;use Illuminate\\Http\\Resources\\Json\\Resource;&#8221; statement with &#8220;use Illuminate\\Http\\Resources\\Json\\JsonResource;&#8221;. This change is necessary because, in the latest versions of Laravel, the Resource class has been deprecated, and JsonResource is the recommended replacement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The error message indicates that the class &#8220;Illuminate\\Http\\Resources\\Json\\Resource&#8221; cannot be found. This typically occurs when attempting to use the Resource class in a resource file. In the&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[556,554,56,555],"class_list":["post-1316","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-jsonresource","tag-illuminatehttpresourcesjsonresource-not-found","tag-not-found","tag-server"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=1316"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1316\/revisions"}],"predecessor-version":[{"id":1318,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1316\/revisions\/1318"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}