Upgrading Laravel 5.5 to 5.6 error

[亡魂溺海] 提交于 2019-11-28 06:47:19

I did this and it works perfectly.

1. composer.json:

From:

"require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0"
    },

To:

"require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0"
    },

2. Replace app\Http\Middleware\TrustedProxies.php file with contents below:

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies;

    /**
     * The headers that should be used to detect proxies.
     *
     * @var string
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

3. composer update

Laravel's Request object extends Symfony's Request object. Laravel 5.5 depends on Symfony 3, which has that constant. Laravel 5.6 depends on Symfony 4, which does not have that constant.

Based on your trusted proxies configuration, it looks like you're using the trusted proxies package "outside" of Laravel. Laravel brought the trusted proxies package inside the framework in 5.5, and created a dedicated \App\Http\Middleware\TrustProxies middleware for you to use.

I would suggest moving to use the middleware and configuring it as described in the Laravel documentation. This will help prevent this type of compatibility issue in the future.

To make the switch:

  1. In app/Http/Kernel.php, if \Fideloper\Proxy\TrustProxies::class is in your $middleware array, remove it. If \App\Http\Middleware\TrustProxies::class is not in your $middleware array, add it.

  2. Open your app/Http/Middleware/TrustProxies.php file and update it with your proxies.

  3. Delete your config/trustedproxy.php file.

  4. Remove Fideloper\Proxy\TrustedProxyServiceProvider::class from your providers array in config/app.php.

  5. Update your composer.json file to use "fideloper/proxy": "~4.0". Run composer update fideloper/proxy to update the package.

Sibin Xavier

I have updated from 5.5 to 5.6

composer.json

"minimum-stability":"dev",
"prefer-stable": true,

This will install latest Laravel packages, then there will be issue with TrustedProxies.

Install the latest proxy version for Laravel 5.6.

Please use tag 4.0+ for Laravel 5.6:

composer require fideloper/proxy:~4.0

More details

First install Laravel 5.6 i faced this error as well. Just follow the few steps below will fix it:

  • Make sure your file composer.json requirement has:
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
            },
  • Then try composer update to make sure your composer is up-to-date
  • Finally run: composer require fideloper/proxy:~4.0
  • Done!

To anyone who tried upgrading directly from laravel 5.5 to 5.7, and got this problem too, remove the trustedproxy.php file from app->config->trustedproxy.php. Hopes that helps someone.

Your problem comes from your use of the library TrustedProxy.

It uses Symfony's HEADER_CLIENT_IP constant which was deprecated with Symfony 3.3 and completely removed in Symfony 4.0.

Since Laravel 5.6 has updated to use Symfony 4 components, this will no longer work.

The way to solve it is to do what patricus suggested and use Laravel's TrustProxies middleware.

I did the following things and got my project to run on Laravel 5.6-dev:

  • Followed what patricus suggested
  • Changed fideloper/proxy to "~4.0", and added "minimum-stability": "dev", "prefer-stable": true at the end of my composer.json file.

Replace app\Http\Middleware\TrustedProxies.php by:

    <?php

  namespace App\Http\Middleware;

  use Illuminate\Http\Request;
  use Fideloper\Proxy\TrustProxies as Middleware;

  class TrustProxies extends Middleware
  {
    protected $proxies;
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
  }

Replace config\trustedproxy.php by:

<?php

return [
    'proxies' => null,
    'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,  
];

None of the suggestions here worked for me for some reason. I am using quickadmin panel and various dependencies which might have something to do with it.

What finally worked was removing laravel/dusk, then updating to "fideloper/proxy": "~4.0", on it's own. Then updating laravel/framework to 5.6, then reinstalling dusk.

I did not need: "minimum-stability":"dev", "prefer-stable": true,

Maybe that was fixed with recent updates.

Faced the same issue and got a number of guidelines to resolve this. Unfortunately none of those worked or me. Actually there is no additional step or tasks needed to be addressed to fix this issue.

Just follow the official upgrade guide from https://laravel.com/docs/5.6/upgrade and along with that remove the trustedproxy config file located at config/trustedproxy.php

Just need to Change fideloper/proxy in composer.json file:-

Your composer.json file now:-

"fideloper/proxy": "~3.3",

Change it to ^4.0 somthing like this:-

"fideloper/proxy": "^4.0",

After that you need to run update composer that's it.

composer update

Had the same issue in Laravel 5.7. You may add TELESCOPE_ENABLED=false in your .env or .env.dusk.local :Source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!