{"id":1297,"date":"2023-11-29T05:55:47","date_gmt":"2023-11-29T05:55:47","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1297"},"modified":"2023-11-29T05:55:48","modified_gmt":"2023-11-29T05:55:48","slug":"updating-laravel-trustproxies-middleware-after-framework-version-upgrade","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/updating-laravel-trustproxies-middleware-after-framework-version-upgrade\/","title":{"rendered":"Updating Laravel TrustProxies Middleware after Framework Version Upgrade"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"304\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-33-1024x304.png\" alt=\"\" class=\"wp-image-1298\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-33-1024x304.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-33-300x89.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-33-768x228.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-33-850x252.png 850w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/11\/image-33.png 1135w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>When upgrading Laravel from version 5.7 to version 10, it&#8217;s essential to address changes in middleware configurations to ensure the smooth operation of your application. The issue related to the <code>TrustProxies<\/code> middleware and provide a solution to update the code for Laravel 10 compatibility.<\/p>\n\n\n\n<p>After upgrading to Laravel 10, the existing <code>TrustProxies<\/code> middleware may become incompatible due to changes in the framework. The middleware is responsible for configuring trusted proxies and headers, and Laravel 10 introduces adjustments to how this is handled.<\/p>\n\n\n\n<p>The Old<code>TrustProxies.php<\/code>:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nnamespace App\\Http\\Middleware;\r\n\r\nuse Illuminate\\Http\\Request;\r\nuse Fideloper\\Proxy\\TrustProxies as Middleware;\r\n\r\nclass TrustProxies extends Middleware\r\n{\r\n    \/**\r\n     * The trusted proxies for this application.\r\n     *\r\n     * @var array\r\n     *\/\r\n    protected $proxies;\r\n\r\n    \/**\r\n     * The current proxy header mappings.\r\n     *\r\n     * @var array\r\n     *\/\r\n    protected $headers = &#91;\r\n        Request::HEADER_FORWARDED => 'FORWARDED',\r\n        Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',\r\n        Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',\r\n        Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',\r\n        Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',\r\n    ];\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>The Solution: To resolve this issue and make the <code>TrustProxies<\/code> middleware compatible with Laravel 10, you should make the following changes:<\/p>\n\n\n\n<p>The Updated <code>TrustProxies.php<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nnamespace App\\Http\\Middleware;\r\n\r\nuse Illuminate\\Http\\Request;\r\nuse Illuminate\\Http\\Middleware\\TrustProxies as Middleware;\r\n\r\nclass TrustProxies extends Middleware\r\n{\r\n    \/**\r\n     * The trusted proxies for this application.\r\n     *\r\n     * @var array|string|null\r\n     *\/\r\n    protected $proxies = '*';\r\n\r\n    \/**\r\n     * The headers that should be used to detect proxies.\r\n     *\r\n     * @var int\r\n     *\/\r\n    protected $headers = Request::HEADER_X_FORWARDED_FOR |\r\n        Request::HEADER_X_FORWARDED_HOST |\r\n        Request::HEADER_X_FORWARDED_PORT |\r\n        Request::HEADER_X_FORWARDED_PROTO |\r\n        Request::HEADER_X_FORWARDED_AWS_ELB;\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>Additionally, ensure that you have the latest version of the <code>fideloper\/proxy<\/code> package installed by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require fideloper\/proxy\r\n<\/code><\/pre>\n\n\n\n<p>Updating middleware configurations is a crucial step when upgrading Laravel versions. By making the necessary adjustments to the <code>TrustProxies<\/code> middleware, you ensure that your application remains compatible with Laravel 10, allowing for a seamless transition and continued stability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When upgrading Laravel from version 5.7 to version 10, it&#8217;s essential to address changes in middleware configurations to ensure the smooth operation of your application. The issue&#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":[539,540,538],"class_list":["post-1297","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-framework-version-upgrade","tag-laravel-trustproxies-middleware","tag-updating-laravel-trustproxies-middleware-after-framework-version-upgrade"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1297","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=1297"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1297\/revisions"}],"predecessor-version":[{"id":1299,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1297\/revisions\/1299"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}