endeavors / components-routing
Endeavors 组件路由包
dev-master
2018-11-20 14:15 UTC
Requires
- endeavors/support-vo: ^2.0
- illuminate/events: ~5.2
- illuminate/routing: ~5.2
- illuminate/support: ~5.2
- nesbot/carbon: ~1.20
Requires (Dev)
- mockery/mockery: ~0.9
- orchestra/testbench: 3.2.x
- phpunit/phpunit: ~5
This package is not auto-updated.
Last update: 2024-09-26 22:57:40 UTC
README
这个库使得在 Laravel 框架的新版本中仅有的某些路由功能变得可用,例如签名 URL(从 Laravel 5.6 开始可用)。
在您的 composer.json 中添加此包并更新 composer。
composer require endeavors/components-routing
安装
更新 composer 后,将 ServiceProvider 添加到 config/app.php 中的 providers 数组。
Endeavors\Components\Routing\FoundationServiceProvider::class,
创建签名路由
您可以使用 URL Facade 创建签名路由。
URL::signedRoute('foo', ['id' => 1, 'username' => 'bob']);
为了方便,可以使用助手函数。
signed_route('foo', ['id' => 1]);
验证
对签名进行验证是在整个 URL 上执行的。
use Illuminate\Support\Facades\Request; public function verifyEmail() { if (Request::hasValidSignature()) { // verify the email } }
您还可以检查请求是否无效。
use Illuminate\Support\Facades\Request; public function verifyEmail() { if (Request::hasInvalidSignature()) { // DON'T verify the email } }
只有在存在特定参数的情况下才能执行验证。
use Illuminate\Support\Facades\Request; public function verifyEmail() { // validate the signature if the email parameter exists if (Request::hasValidParameterSignature(['email'])) { // verify the email } }
再次,您还可以检查请求是否有无效的签名。
use Illuminate\Support\Facades\Request; public function verifyEmail() { // validate the signature if the email parameter exists if (Request::hasInvalidParameterSignature(['email'])) { // DON'T verify the email } }