alcaitiff/laravel-urlencode

允许在路由参数中编码斜杠和其他字符

1.0.2 2020-04-22 18:10 UTC

This package is auto-updated.

Last update: 2024-09-23 04:00:27 UTC


README

覆盖Laravel 5的默认路由,允许包括斜杠在内的所有字符进行编码!

本项目是对https://github.com/Artistan/Urlencode的改编,允许该修复在Laravel 5中工作

Composer配置

将Artistan urlencode包作为依赖项包含在您的composer.jsonPackagist

    "alcaitiff/laravel-urlencode:"1.*"

或者执行以下命令

    composer require alcaitiff/laravel-urlencode:"1.*"

安装

更新您的composer配置后,运行composer install以下载依赖项。

app/config/app.php中将ServiceProvider添加到您的providers数组中

  'providers' => [
    ...
    Alcaitiff\LaravelUrlEncode\RouteServiceProvider::class,
    ...
  ];

在您的App\Http\Kernel上添加一个方法以允许路由替换

  //This is needed because Laravel DO NOT use his own service provider system
  //You can't change the app router and the kernel router through the dependency injection
  //The framework set a router at the very beginning of the stack and do not allow changes
  //We can only hope in future implementations actually using the injection system allowing that
  public function setRouter(Router $router) {
    $this->router = $router;
    return $this;
  }

Apache conf AllowEncodedSlashes

  AllowEncodedSlashes On|NoDecode

警告

确保您的所有路由都正确进行了原始URL编码!

如果没有在您的路由中提供有效的URL,此包实际上会破坏您的路由。

Laravel Bug修复

[Bug] 路由参数中的urlencoded斜杠当前路由不允许路径中有urlencoded斜杠。当尝试创建包含斜杠的零件编号的路由的电子商务解决方案时,这可能会出现问题,因为许多零件编号包含斜杠。还有一些制造商的名字或品牌中包含斜杠。此包提供了在路由中允许uri具有编码斜杠和其他字符的功能,并且还可以使用这些参数创建路由

一个示例URL可能如下所示...

  //https://stage.test.com/part/Cisco%20Systems%2C%20Inc/CISCO2851-SRST%2FK9
    Route::any('/part/{mfg}/{part}',
        array(
            'uses' =>'Vendorname\Package\Controllers\Hardware\PartController@part',
            'as' => 'part_page'
        )
    );

用法

话虽如此,它确实会允许所有字符作为参数在您的路由中进行原始URL编码,而不会破坏参数和/或路由。