首页 > 解决方案 > Laravel preg_match uri 验证器

问题描述

我正在使用 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));
    }
}

标签: phplaravel

解决方案


在你的 web.php 中试试这个

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

推荐阅读