php 将 Laravel 5.5 升级到 5.6 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48594851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:42:19  来源:igfitidea点击:

Upgrading Laravel 5.5 to 5.6 error

phplaravelcomposer-phplaravel-5.6

提问by Candy

I am trying to upgrade my Laravel 5.5to 5.6.I have followed the instructions from the laravelwebsite, yet I got this error:

我正在尝试将我的 Laravel 升级5.55.6.我已按照laravel网站上的说明进行操作,但出现此错误:

Your requirements could not be resolved to an installable set of packages.
    Problem 1
        - The requested package laravel/framework 5.6.* is satisfiable by laravel/framework[5.6.x-dev] but these conflict with your requirements or minimum-stability.

So, I changed my composer.jsonfile and added 2 lines: **"minimum-stability": "dev", "prefer-stable": true,**based on the first answer on thislaracast discussion.

因此,我更改了我的composer.json文件并添加了 2 行:**"minimum-stability": "dev", "prefer-stable": true,**基于laracast 讨论的第一个答案。

Everything seemed to be working just fine until I got another error:

一切似乎都很好,直到我遇到另一个错误:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 6 updates, 0 removals
  - Updating sebastian/diff (2.0.1 => 3.0.0): Downloading (100%)         
  - Updating phpunit/phpunit-mock-objects (5.0.6 => 6.0.0): Downloading (100%)    - Updating phpunit/php-timer (1.0.9 => 2.0.0): Downloading (100%)         
  - Updating phpunit/php-token-stream (2.0.2 => 3.0.0): Downloading (100%)        - Updating phpunit/php-code-coverage (5.3.0 => 6.0.1): Downloading (100%)       - Updating phpunit/phpunit (6.5.6 => 7.0.0): Downloading (100%)         
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover

In trustedproxy.php line 66:

  Undefined class constant 'HEADER_CLIENT_IP'  


Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

The problem on line 66 is Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',. I have searched other posts on stackoverflow but still no luck. The last thing I tried was composer selfupdate and composer global update which was mentioned on the post composer dump-autoload not recognized command

第 66 行的问题是Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',。我在 stackoverflow 上搜索了其他帖子,但仍然没有运气。我尝试的最后一件事是 composer selfupdate 和 composer global update 这在 post composer dump-autoload not识别命令中提到

Also, I cannot remove "minimum-stability": "dev","prefer-stable": true because if I do, then I will get the following error:

此外,我无法删除 "minimum-stability": "dev","prefer-stable": true 因为如果我这样做,那么我将收到以下错误:

    - Installation request for laravel/framework 5.6.* -> satisfiable by laravel/framework[5.6.x-dev].
- Removal request for laravel/framework == 5.6.9999999.9999999-dev

I have attached my composer.json file and trustedproxy.php respectively. Any help will be highly appreciated.

我分别附上了我的 composer.json 文件和 trustproxy.php。任何帮助将不胜感激。

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "minimum-stability": "dev",
"prefer-stable": true,
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~7.0",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

trustedproxy.php (error in line 66--> Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',)

可信代理.php (error in line 66--> Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',)

<?php

return [

    /*
     * Set trusted proxy IP addresses.
     *
     * Both IPv4 and IPv6 addresses are
     * supported, along with CIDR notation.
     *
     * The "*" character is syntactic sugar
     * within TrustedProxy to trust any proxy
     * that connects directly to your server,
     * a requirement when you cannot know the address
     * of your proxy (e.g. if using Rackspace balancers).
     *
     * The "**" character is syntactic sugar within
     * TrustedProxy to trust not just any proxy that
     * connects directly to your server, but also
     * proxies that connect to those proxies, and all
     * the way back until you reach the original source
     * IP. It will mean that $request->getClientIp()
     * always gets the originating client IP, no matter
     * how many proxies that client's request has
     * subsequently passed through.
     */
    'proxies' => [
        '192.168.1.10',
    ],

    /*
     * Or, to trust all proxies that connect
     * directly to your server, uncomment this:
     */
     # 'proxies' => '*',

    /*
     * Or, to trust ALL proxies, including those that
     * are in a chain of forwarding, uncomment this:
    */
    # 'proxies' => '**',

    /*
     * Default Header Names
     *
     * Change these if the proxy does
     * not send the default header names.
     *
     * Note that headers such as X-Forwarded-For
     * are transformed to HTTP_X_FORWARDED_FOR format.
     *
     * The following are Symfony defaults, found in
     * \Symfony\Component\HttpFoundation\Request::$trustedHeaders
     *
     * You may optionally set headers to 'null' here if you'd like
     * for them to be considered untrusted instead. Ex:
     *
     * Illuminate\Http\Request::HEADER_CLIENT_HOST  => null,
     * 
     * WARNING: If you're using AWS Elastic Load Balancing or Heroku,
     * the FORWARDED and X_FORWARDED_HOST headers should be set to null 
     * as they are currently unsupported there.
     */
    'headers' => [
        (defined('Illuminate\Http\Request::HEADER_FORWARDED') ? Illuminate\Http\Request::HEADER_FORWARDED : 'forwarded') => 'FORWARDED',
        Illuminate\Http\Request::HEADER_CLIENT_IP    => 'X_FORWARDED_FOR',
        Illuminate\Http\Request::HEADER_CLIENT_HOST  => 'X_FORWARDED_HOST',
        Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
        Illuminate\Http\Request::HEADER_CLIENT_PORT  => 'X_FORWARDED_PORT',
    ]
];

Illuminate\Http\Request file:

Illuminate\Http\Request 文件:

<?php

namespace Illuminate\Http;

use Closure;
use ArrayAccess;
use RuntimeException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Arrayable;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

class Request extends SymfonyRequest implements Arrayable, ArrayAccess
{
    use Concerns\InteractsWithContentTypes,
        Concerns\InteractsWithFlashData,
        Concerns\InteractsWithInput,
        Macroable;

    /**
     * The decoded JSON content for the request.
     *
     * @var \Symfony\Component\HttpFoundation\ParameterBag|null
     */
    protected $json;

    /**
     * All of the converted files for the request.
     *
     * @var array
     */
    protected $convertedFiles;

    /**
     * The user resolver callback.
     *
     * @var \Closure
     */
    protected $userResolver;

    /**
     * The route resolver callback.
     *
     * @var \Closure
     */
    protected $routeResolver;

    /**
     * Create a new Illuminate HTTP request from server variables.
     *
     * @return static
     */
    public static function capture()
    {
        static::enableHttpMethodParameterOverride();

        return static::createFromBase(SymfonyRequest::createFromGlobals());
    }

    /**
     * Return the Request instance.
     *
     * @return $this
     */
    public function instance()
    {
        return $this;
    }

    /**
     * Get the request method.
     *
     * @return string
     */
    public function method()
    {
        return $this->getMethod();
    }

    /**
     * Get the root URL for the application.
     *
     * @return string
     */
    public function root()
    {
        return rtrim($this->getSchemeAndHttpHost().$this->getBaseUrl(), '/');
    }

    /**
     * Get the URL (no query string) for the request.
     *
     * @return string
     */
    public function url()
    {
        return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
    }

    /**
     * Get the full URL for the request.
     *
     * @return string
     */
    public function fullUrl()
    {
        $query = $this->getQueryString();

        $question = $this->getBaseUrl().$this->getPathInfo() == '/' ? '/?' : '?';

        return $query ? $this->url().$question.$query : $this->url();
    }

    /**
     * Get the full URL for the request with the added query string parameters.
     *
     * @param  array  $query
     * @return string
     */
    public function fullUrlWithQuery(array $query)
    {
        $question = $this->getBaseUrl().$this->getPathInfo() == '/' ? '/?' : '?';

        return count($this->query()) > 0
            ? $this->url().$question.http_build_query(array_merge($this->query(), $query))
            : $this->fullUrl().$question.http_build_query($query);
    }

    /**
     * Get the current path info for the request.
     *
     * @return string
     */
    public function path()
    {
        $pattern = trim($this->getPathInfo(), '/');

        return $pattern == '' ? '/' : $pattern;
    }

    /**
     * Get the current decoded path info for the request.
     *
     * @return string
     */
    public function decodedPath()
    {
        return rawurldecode($this->path());
    }

    /**
     * Get a segment from the URI (1 based index).
     *
     * @param  int  $index
     * @param  string|null  $default
     * @return string|null
     */
    public function segment($index, $default = null)
    {
        return Arr::get($this->segments(), $index - 1, $default);
    }

    /**
     * Get all of the segments for the request path.
     *
     * @return array
     */
    public function segments()
    {
        $segments = explode('/', $this->decodedPath());

        return array_values(array_filter($segments, function ($value) {
            return $value !== '';
        }));
    }

    /**
     * Determine if the current request URI matches a pattern.
     *
     * @param  dynamic  $patterns
     * @return bool
     */
    public function is(...$patterns)
    {
        foreach ($patterns as $pattern) {
            if (Str::is($pattern, $this->decodedPath())) {
                return true;
            }
        }

        return false;
    }

    /**
     * Determine if the route name matches a given pattern.
     *
     * @param  dynamic  $patterns
     * @return bool
     */
    public function routeIs(...$patterns)
    {
        return $this->route() && $this->route()->named(...$patterns);
    }

    /**
     * Determine if the current request URL and query string matches a pattern.
     *
     * @param  dynamic  $patterns
     * @return bool
     */
    public function fullUrlIs(...$patterns)
    {
        $url = $this->fullUrl();

        foreach ($patterns as $pattern) {
            if (Str::is($pattern, $url)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Determine if the request is the result of an AJAX call.
     *
     * @return bool
     */
    public function ajax()
    {
        return $this->isXmlHttpRequest();
    }

    /**
     * Determine if the request is the result of an PJAX call.
     *
     * @return bool
     */
    public function pjax()
    {
        return $this->headers->get('X-PJAX') == true;
    }

    /**
     * Determine if the request is over HTTPS.
     *
     * @return bool
     */
    public function secure()
    {
        return $this->isSecure();
    }

    /**
     * Get the client IP address.
     *
     * @return string
     */
    public function ip()
    {
        return $this->getClientIp();
    }

    /**
     * Get the client IP addresses.
     *
     * @return array
     */
    public function ips()
    {
        return $this->getClientIps();
    }

    /**
     * Get the client user agent.
     *
     * @return string
     */
    public function userAgent()
    {
        return $this->headers->get('User-Agent');
    }

    /**
     * Merge new input into the current request's input array.
     *
     * @param  array  $input
     * @return \Illuminate\Http\Request
     */
    public function merge(array $input)
    {
        $this->getInputSource()->add($input);

        return $this;
    }

    /**
     * Replace the input for the current request.
     *
     * @param  array  $input
     * @return \Illuminate\Http\Request
     */
    public function replace(array $input)
    {
        $this->getInputSource()->replace($input);

        return $this;
    }

    /**
     * Get the JSON payload for the request.
     *
     * @param  string  $key
     * @param  mixed   $default
     * @return \Symfony\Component\HttpFoundation\ParameterBag|mixed
     */
    public function json($key = null, $default = null)
    {
        if (! isset($this->json)) {
            $this->json = new ParameterBag((array) json_decode($this->getContent(), true));
        }

        if (is_null($key)) {
            return $this->json;
        }

        return data_get($this->json->all(), $key, $default);
    }

    /**
     * Get the input source for the request.
     *
     * @return \Symfony\Component\HttpFoundation\ParameterBag
     */
    protected function getInputSource()
    {
        if ($this->isJson()) {
            return $this->json();
        }

        return $this->getRealMethod() == 'GET' ? $this->query : $this->request;
    }

    /**
     * Create an Illuminate request from a Symfony instance.
     *
     * @param  \Symfony\Component\HttpFoundation\Request  $request
     * @return \Illuminate\Http\Request
     */
    public static function createFromBase(SymfonyRequest $request)
    {
        if ($request instanceof static) {
            return $request;
        }

        $content = $request->content;

        $request = (new static)->duplicate(
            $request->query->all(), $request->request->all(), $request->attributes->all(),
            $request->cookies->all(), $request->files->all(), $request->server->all()
        );

        $request->content = $content;

        $request->request = $request->getInputSource();

        return $request;
    }

    /**
     * {@inheritdoc}
     */
    public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
    {
        return parent::duplicate($query, $request, $attributes, $cookies, $this->filterFiles($files), $server);
    }

    /**
     * Filter the given array of files, removing any empty values.
     *
     * @param  mixed  $files
     * @return mixed
     */
    protected function filterFiles($files)
    {
        if (! $files) {
            return;
        }

        foreach ($files as $key => $file) {
            if (is_array($file)) {
                $files[$key] = $this->filterFiles($files[$key]);
            }

            if (empty($files[$key])) {
                unset($files[$key]);
            }
        }

        return $files;
    }

    /**
     * Get the session associated with the request.
     *
     * @return \Illuminate\Session\Store
     *
     * @throws \RuntimeException
     */
    public function session()
    {
        if (! $this->hasSession()) {
            throw new RuntimeException('Session store not set on request.');
        }

        return $this->session;
    }

    /**
     * Get the session associated with the request.
     *
     * @return \Illuminate\Session\Store|null
     */
    public function getSession()
    {
        return $this->session;
    }

    /**
     * Set the session instance on the request.
     *
     * @param  \Illuminate\Contracts\Session\Session  $session
     * @return void
     */
    public function setLaravelSession($session)
    {
        $this->session = $session;
    }

    /**
     * Get the user making the request.
     *
     * @param  string|null  $guard
     * @return mixed
     */
    public function user($guard = null)
    {
        return call_user_func($this->getUserResolver(), $guard);
    }

    /**
     * Get the route handling the request.
     *
     * @param  string|null  $param
     *
     * @return \Illuminate\Routing\Route|object|string
     */
    public function route($param = null)
    {
        $route = call_user_func($this->getRouteResolver());

        if (is_null($route) || is_null($param)) {
            return $route;
        }

        return $route->parameter($param);
    }

    /**
     * Get a unique fingerprint for the request / route / IP address.
     *
     * @return string
     *
     * @throws \RuntimeException
     */
    public function fingerprint()
    {
        if (! $route = $this->route()) {
            throw new RuntimeException('Unable to generate fingerprint. Route unavailable.');
        }

        return sha1(implode('|', array_merge(
            $route->methods(), [$route->getDomain(), $route->uri(), $this->ip()]
        )));
    }

    /**
     * Set the JSON payload for the request.
     *
     * @param  \Symfony\Component\HttpFoundation\ParameterBag  $json
     * @return $this
     */
    public function setJson($json)
    {
        $this->json = $json;

        return $this;
    }

    /**
     * Get the user resolver callback.
     *
     * @return \Closure
     */
    public function getUserResolver()
    {
        return $this->userResolver ?: function () {
            //
        };
    }

    /**
     * Set the user resolver callback.
     *
     * @param  \Closure  $callback
     * @return $this
     */
    public function setUserResolver(Closure $callback)
    {
        $this->userResolver = $callback;

        return $this;
    }

    /**
     * Get the route resolver callback.
     *
     * @return \Closure
     */
    public function getRouteResolver()
    {
        return $this->routeResolver ?: function () {
            //
        };
    }

    /**
     * Set the route resolver callback.
     *
     * @param  \Closure  $callback
     * @return $this
     */
    public function setRouteResolver(Closure $callback)
    {
        $this->routeResolver = $callback;

        return $this;
    }

    /**
     * Get all of the input and files for the request.
     *
     * @return array
     */
    public function toArray()
    {
        return $this->all();
    }

    /**
     * Determine if the given offset exists.
     *
     * @param  string  $offset
     * @return bool
     */
    public function offsetExists($offset)
    {
        return array_key_exists(
            $offset, $this->all() + $this->route()->parameters()
        );
    }

    /**
     * Get the value at the given offset.
     *
     * @param  string  $offset
     * @return mixed
     */
    public function offsetGet($offset)
    {
        return $this->__get($offset);
    }

    /**
     * Set the value at the given offset.
     *
     * @param  string  $offset
     * @param  mixed  $value
     * @return void
     */
    public function offsetSet($offset, $value)
    {
        $this->getInputSource()->set($offset, $value);
    }

    /**
     * Remove the value at the given offset.
     *
     * @param  string  $offset
     * @return void
     */
    public function offsetUnset($offset)
    {
        $this->getInputSource()->remove($offset);
    }

    /**
     * Check if an input element is set on the request.
     *
     * @param  string  $key
     * @return bool
     */
    public function __isset($key)
    {
        return ! is_null($this->__get($key));
    }

    /**
     * Get an input element from the request.
     *
     * @param  string  $key
     * @return mixed
     */
    public function __get($key)
    {
        if (array_key_exists($key, $this->all())) {
            return data_get($this->all(), $key);
        }

        return $this->route($key);
    }
}

Thanks

谢谢

回答by user1040259

I did this and it works perfectly.

我这样做了,而且效果很好。

1. composer.json:

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:

2. 将 app\Http\Middleware\TrustedProxies.php 文件替换为以下内容:

<?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

3.作曲家更新

回答by patricus

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.

Laravel 的 Request 对象扩展了 Symfony 的 Request 对象。Laravel 5.5 依赖于具有该常数的 Symfony 3。Laravel 5.6 依赖于 Symfony 4,它没有那个常数。

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\TrustProxiesmiddleware for you to use.

根据您的受信任代理配置,您似乎正在使用 Laravel “外部”的受信任代理包。Laravel 在 5.5 的框架中引入了受信任的代理包,并创建了一个专用的\App\Http\Middleware\TrustProxies中间件供您使用。

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.

我建议使用中间件并按照Laravel 文档中的描述对其进行配置。这将有助于防止将来出现此类兼容性问题。

To make the switch:

要进行切换:

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

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

  3. Delete your config/trustedproxy.phpfile.

  4. Remove Fideloper\Proxy\TrustedProxyServiceProvider::classfrom your providersarray in config/app.php.

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

  1. In app/Http/Kernel.php,如果\Fideloper\Proxy\TrustProxies::class在您的$middleware数组中,请将其删除。如果\App\Http\Middleware\TrustProxies::class不在您的$middleware数组中,请添加它。

  2. 打开您的app/Http/Middleware/TrustProxies.php文件并使用您的代理更新它。

  3. 删除您的config/trustedproxy.php文件。

  4. 删除Fideloper\Proxy\TrustedProxyServiceProvider::class从您providers的阵列config/app.php

  5. 更新您的 composer.json 文件以使用“fideloper/proxy”:“~4.0”。运行composer update fideloper/proxy以更新包。

回答by Sibin Xavier

I have updated from 5.5 to 5.6

我已经从 5.5 更新到 5.6

composer.json

作曲家.json

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

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

这将安装最新的 Laravel 软件包,然后会出现TrustedProxies.

Install the latest proxy version for Laravel 5.6.

安装 Laravel 5.6 的最新代理版本。

Please use tag 4.0+ for Laravel 5.6:

请为 Laravel 5.6 使用标签 4.0+:

composer require fideloper/proxy:~4.0

More details

更多细节

回答by Vanndy

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

首先安装Laravel 5.6我也遇到了这个错误。只需按照以下几个步骤即可修复它:

  • Make sure your file composer.jsonrequirement has:
  • 确保您的文件composer.json要求具有:
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
            },
  • Then try composer updateto make sure your composer is up-to-date
  • Finally run: composer require fideloper/proxy:~4.0
  • Done!
  • 然后尝试composer update确保您的作曲家是最新的
  • 最后运行: composer require fideloper/proxy:~4.0
  • 完毕!

回答by Pawan Verma

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

只需要在 composer.json 文件中更改 fideloper/proxy :-

Your composer.json file now:-

您现在的 composer.json 文件:-

"fideloper/proxy": "~3.3",

Change it to ^4.0 somthing like this:-

将其更改为 ^4.0,如下所示:-

"fideloper/proxy": "^4.0",

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

之后,您需要运行更新作曲家就是这样。

composer update

回答by GabMic

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.

对于尝试直接从 laravel 5.5 升级到 5.7 并且也遇到此问题的任何人,请从app->config->trustedproxy.php. 希望对某人有所帮助。

回答by Candy

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

我做了以下事情并让我的项目在 Laravel 5.6-dev 上运行:

  • Followed what patricus suggested
  • Changed fideloper/proxy to "~4.0", and added "minimum-stability": "dev", "prefer-stable": trueat the end of my composer.json file.
  • 遵循帕特里克斯的建议
  • 将 fideloper/proxy 更改为“~4.0”,并添加"minimum-stability": "dev", "prefer-stable": true到我的 composer.json 文件的末尾。

回答by Daniel

Your problem comes from your use of the library TrustedProxy.

您的问题来自您对库TrustedProxy 的使用

It uses Symfony's HEADER_CLIENT_IPconstant which was deprecatedwith Symfony 3.3 and completely removed in Symfony 4.0.

它使用 Symfony 的HEADER_CLIENT_IP常量,该常量在 Symfony 3.3 中被弃用并在 Symfony 4.0 中完全删除。

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

由于 Laravel 5.6 已更新为使用 Symfony 4 组件,这将不再有效。

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

解决它的方法是按照patricus 的建议并使用 Laravel 的 TrustProxies 中间件。

回答by Mehdi

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

将 app\Http\Middleware\TrustedProxies.php 替换为:

    <?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:

将 config\trustedproxy.php 替换为:

<?php

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

回答by fred

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.

出于某种原因,这里的任何建议都不适合我。我正在使用 quickadmin 面板和可能与它有关的各种依赖项。

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.

最终有效的是删除 laravel/dusk,然后"fideloper/proxy": "~4.0",自行更新。然后更新laravel/framework 到5.6,然后重新安装dusk。

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

我不需要: "minimum-stability":"dev", "prefer-stable": true,

Maybe that was fixed with recent updates.

也许最近的更新已经解决了这个问题。