【问题标题】:Laravel preg_match uri validatorLaravel preg_match uri 验证器
【发布时间】:2019-12-22 13:44:37
【问题描述】:

我正在使用 Laravel 和 Vue 安装一些应用程序,我使用的是 php 7.3,但 laravel 运行的是 5.6。 现在给我一个错误,例如:

preg_match():编译失败:字符类中的无效范围 偏移 20

在文件夹 vendor\laravel\framework\src\Illuminate\Routing\Matching\UriValidator.php

这里是代码

<?php

namespace Illuminate\Routing\Matching;

use Illuminate\Http\Request;
use Illuminate\Routing\Route;

class UriValidator implements ValidatorInterface
{
    /**
     * Validate a given rule against a route and request.
     *
     * @param  \Illuminate\Routing\Route  $route
     * @param  \Illuminate\Http\Request  $request
     * @return bool
     */
    public function matches(Route $route, Request $request)
    {
        $path = $request->path() == '/' ? '/' : '/'.$request->path();

        return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
    }
}

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    在你的 web.php 中试试这个

    Route::get('{path}',function(){
     return view('your.index');
    })->where('path', '[A-z\d\-\/_.]+');
    

    【讨论】:

    • 您好,感谢您的回答。如果你能解释你的代码是做什么的,那就太好了。以这种方式向您学习将有助于社区更多!
    • 我在 github 上找到了这个解决方案。据我了解,路线与路径中的字符不匹配。最初我将它设置为 [path, '*'] ,但它没有帮助。
    猜你喜欢
    • 1970-01-01
    • 2012-02-09
    • 2014-01-20
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2015-04-21
    相关资源
    最近更新 更多