承接 shiftonelabs/laravel-singular-resource-routes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shiftonelabs/laravel-singular-resource-routes

Composer 安装命令:

composer require shiftonelabs/laravel-singular-resource-routes

包简介

Adds support for singular resource routes to the Laravel router.

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This Laravel package adds support for singular resource routes to Laravel's router.

Sometimes you need to deal with a resource that does not need to be referenced by the id. For example, you may have a profile resource that belongs to the currently authenticated user. Currently, if you wanted to show the user's profile, the route would be /profile/{profile}. However, since you don't need the id to look up the current user's profile, it would be nice to be able to simply have the show route be /profile. This is the same for the edit, update, and destroy routes, as well.

The singular resource route generates the following routes:

Verb Path Action Route Name
GET /profile/create create profile.create
POST /profile store profile.store
GET /profile show profile.show
GET /profile/edit edit profile.edit
PUT/PATCH /profile update profile.update
DELETE /profile destroy profile.destroy

These routes differ from the current resource routes in two ways:

  1. The show, edit, update, and destroy routes do not need a route parameter.
  2. Since this is a singular resource, there is no index action.

Versions

This package has been tested on Laravel 5.0 through Laravel 8.x, though it may continue to work on later versions as they are released. This section will be updated to reflect the versions on which the package has actually been tested.

Install

Via Composer

composer require shiftonelabs/laravel-singular-resource-routes

Service Provider

This package supports Laravel package autodiscovery. So, if using Laravel 5.5+, there is no need to add the server provider. If using Laravel 5.0 - 5.4, add the service provider to your config/app.php file:

'providers' => [
    ...
    ShiftOneLabs\SingularResourceRoutes\SingularResourceRoutesServiceProvider::class,
];

Usage

In order to create a new singular resource route, a new singular option is added to the resource route definition. This option can be set to three different values:

  1. The boolean true. This is mainly for non-nested resource definitions. If it is used on a nested resource definition, only the last resource in the chain will be treated as singular.
  2. A string containing the name of the singular resource. This can be used when there is only one resource that is singular in a nested resource definition. The string must contain the name of the singular resource.
  3. An array of strings containing the names of the singular resources. This format must be used when there are multiple singular resources in a nested resource definition, but it can be used in any scenario.

Code Example

A singular resource (/profile):

// Since there is only one singular resource, and it is the last one,
// all three options work in this scenario.

Route::resource('profile', 'ProfileController', ['singular' => true]);
Route::resource('profile', 'ProfileController', ['singular' => 'profile']);
Route::resource('profile', 'ProfileController', ['singular' => ['profile']]);

A singular resource nested under a plural resource (/users/{user}/profile):

// Since there is only one singular resource, and it is the last one,
// all three options work in this scenario.

Route::resource('users.profile', 'ProfileController', ['singular' => true]);
Route::resource('users.profile', 'ProfileController', ['singular' => 'profile']);
Route::resource('users.profile', 'ProfileController', ['singular' => ['profile']]);

A singular resource nested under a singular resource (/profile/avatar):

// Since there are multiple resources that are singular, only the array
// syntax can be used to specify all the singular resources.

Route::resource('profile.avatar', 'ProfileAvatarController', ['singular' => ['profile', 'avatar']]);

A plural resource nested under a singular resource (/profile/phones/{phone}):

// Since there is a parent resource that is singular, the "true" option cannot be used.
// But since there is only one singular resource, the string option can be used.

Route::resource('profile.phones', 'PhoneController', ['singular' => 'profile']);
Route::resource('profile.phones', 'PhoneController', ['singular' => ['profile']]);

A singular resource nested under a plural resource nested under a singular resource (/profile/phones/{phone}/type):

// Since there are multiple resources that are singular, only the array
// syntax can be used to specify all the singular resources.

Route::resource('profile.phones.type', 'PhoneTypeController', ['singular' => ['profile', 'type']]);

Contributing

Contributions are welcome. Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email patrick@shiftonelabs.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

shiftonelabs/laravel-singular-resource-routes 适用场景与选型建议

shiftonelabs/laravel-singular-resource-routes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.79k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2018 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「routes」 「laravel」 「resource」 「singular」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shiftonelabs/laravel-singular-resource-routes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shiftonelabs/laravel-singular-resource-routes 我们能提供哪些服务?
定制开发 / 二次开发

基于 shiftonelabs/laravel-singular-resource-routes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-15