humans/laravel-singleton-routes

此包已被废弃,不再维护。未建议替代包。

为Laravel添加单例路由。

0.3.0 2022-01-27 12:19 UTC

This package is auto-updated.

Last update: 2023-11-27 16:17:52 UTC


README

这是一个为Laravel添加Rails/Phoenix单例路由支持的包。单例路由,或称为单数资源路由,是不需要以标识符为上下文的路由。

与标准资源路由不同,单例路由没有索引方法。

例如,更新当前用户的详细信息。

show      GET         /my/profile
create    GET         /my/profile/create
store     POST        /my/profile
edit      GET         /my/profile/edit
update    PUT|PATCH   /my/profile
destroy   DELETE      /my/profile

安装和用法

使用composer安装此包

composer require humans/laravel-singleton-routes

注册单例路由。

Route::singleton('profile', PasswordController::class);

注册嵌套单例路由。

Route::singleton('accounts.suspension', AccountSuspensionController::class)
  ->only('show', 'store', 'destroy');

与其他Laravel资源一样,您将可以访问资源方法,如 middlewareonlyexcept。目前,在调用Route方法后无法对其进行链式调用。Route::prefix()->singleton() 不会 工作。

将注册包裹在一个组中可以使其工作。

Route::prefix('admin')->as('admin.')->group(function () {
  Route::singleton('theme', ThemeController::class)->only('update');
  // url  =>   PUT|PATCH  /admin/theme
  // name =>   admin.theme.update
});