sjorsvanleeuwen / laravel-extended-resource-registrar
该包已被放弃,不再维护。作者建议使用 sjorsvanleeuwen/route-resource-extension 包。
Laravel 路由器和 ResourceRegistrar 扩展,用于处理软删除和无 HTTP DELETE 方法的简单删除
0.6
2019-01-31 19:06 UTC
Requires
- laravel/framework: 5.7.*
README
这是一个用于扩展 Laravel 5 资源注册器的包。它包括一个 ServiceProvider 用于注册新的路由。
安装
使用 composer 安装此包。建议仅在开发时使用此包。
composer require sjorsvanleeuwen/laravel-extended-resource-registrar
Laravel 5.5 使用包自动发现,因此无需手动添加 ServiceProvider。
确保将 app/Http/Kernel.php 修改如下
/** * Get the route dispatcher callback. * Do this to make the new Router work * * @return \Closure */ protected function dispatchToRouter() { $this->router = $this->app['router']; foreach ($this->middlewareGroups as $key => $middleware) { $this->router->middlewareGroup($key, $middleware); } foreach ($this->routeMiddleware as $key => $middleware) { $this->router->aliasMiddleware($key, $middleware); } return parent::dispatchToRouter(); }
添加此功能的原因:默认路由器已在其他 ServiceProvider 加载之前绑定并传递给内核,内核不知道新的路由器,因此无法加载已注册的路由,因为这些路由是用新路由器注册的,而 public/index.php 中绑定的内核有默认路由器。
Laravel 5.5+
如果您不使用自动发现,请将 ServiceProvider 添加到 config/app.php 中的 providers 数组中
Sjorsvanleeuwen\ExtendedResourceRegistrar\ServiceProvider::class,
Lumen
未在 Lumen 上测试
用法
现在您可以使用 softDeletes 创建资源路由
Route::resource('foo', 'FooController')->withSoftDeletes();