承接 dragon-code/laravel-route-names 相关项目开发

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

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

dragon-code/laravel-route-names

Composer 安装命令:

composer require dragon-code/laravel-route-names

包简介

Automatic generation of route names

README 文档

README

Laravel Route Names

Stable Version Total Downloads Github Workflow Status License

Installation

To get the latest version of Laravel Route Names, simply require the project using Composer:

composer require dragon-code/laravel-route-names

Warning

For naming to work correctly, you need to replace the application class otherwise the code will be loaded too late.

To do this, replace Illuminate\Foundation\Application with DragonCode\LaravelRouteNames\Application in the bootstrap/app.php file.

You can now list the routes, for example by calling the php artisan route:list command or by using the dragon-code/pretty-routes package.

Using

This is all. Now you don't have to specify route names. Now the route names will be generated automatically based on the final URL of your project.

All previously specified route names in the application will be ignored.

Compatible with all package solutions for expanding the list of routes.

Since route names are generated at the time they are received, we recommend using route caching in production:

php artisan route:cache

// or

php artisan optimize

Base Routes

app('router')->get('/', [IndexController::class, 'index']);
app('router')->post('/', [IndexController::class, 'store']);
app('router')->put('/', [IndexController::class, 'update']);
app('router')->delete('/', [IndexController::class, 'delete']);
app('router')->patch('/', [IndexController::class, 'patch']);
app('router')->options('/', [IndexController::class, 'options']);

app('router')->get('{some}', [IndexController::class, 'index']);
app('router')->post('{some}', [IndexController::class, 'store']);
app('router')->put('{some}', [IndexController::class, 'update']);
app('router')->delete('{some}', [IndexController::class, 'delete']);
app('router')->patch('{some}', [IndexController::class, 'patch']);
app('router')->options('{some}', [IndexController::class, 'options']);

app('router')->get('pages', [PagesController::class, 'index']);
app('router')->post('pages', [PagesController::class, 'store']);
app('router')->put('pages/{page}', [PagesController::class, 'update']);
app('router')->delete('pages/{page}', [PagesController::class, 'delete']);
app('router')->patch('pages/{page}', [PagesController::class, 'patch']);
app('router')->options('pages/{page}', [PagesController::class, 'options']);
Method Url Name Helper
GET, HEAD / main.index route('main.index')
POST / main.store route('main.store')
PUT / main.update route('main.update')
DELETE / main.destroy route('main.destroy')
PATCH / main.patch route('main.patch')
OPTIONS / main.options route('main.options')
GET, HEAD {some} some.index route('some.index')
POST {some} some.store route('some.store')
PUT {some} some.update route('some.update')
DELETE {some} some.destroy route('some.destroy')
PATCH {some} some.patch route('some.patch')
OPTIONS {some} some.options route('some.options')
GET, HEAD /pages pages.index route('pages.index')
POST /pages pages.store route('pages.store')
PUT /pages/123 pages.update route('pages.update')
DELETE /pages/123 pages.destroy route('pages.destroy')
PATCH /pages/123 pages.patch route('pages.patch')
OPTIONS /pages/123 pages.options route('pages.options')

Resource Routes

app('router')->resource('authors/{author}/photos', Author\PhotoController::class);
Method Url Name Helper
GET, HEAD /authors/123/photos authors.photos.index route('authors.photos.index')
GET, HEAD /authors/123/photos/create authors.photos.create route('authors.photos.create')
POST /authors/123/photos authors.photos.store route('authors.photos.store')
GET /authors/123/photos/{photo} authors.photos.show route('authors.photos.show')
GET /authors/123/photos/{photo}/edit authors.photos.edit route('authors.photos.edit')
PUT /authors/123/photos/{photo} authors.photos.update route('authors.photos.update')
PATCH /authors/123/photos/{photo} authors.photos.patch route('authors.photos.patch')
DELETE /authors/123/photos/{photo} authors.photos.destroy route('authors.photos.destroy')

API Resource Routes

app('router')->apiResource('authors/{author}/photos', Author\PhotoController::class);
Method Url Name Helper
GET, HEAD /authors/123/photos authors.photos.index route('authors.photos.index')
POST /authors/123/photos authors.photos.store route('authors.photos.store')
GET /authors/123/photos/{photo} authors.photos.show route('authors.photos.show')
PUT /authors/123/photos/{photo} authors.photos.update route('authors.photos.update')
PATCH /authors/123/photos/{photo} authors.photos.patch route('authors.photos.patch')
DELETE /authors/123/photos/{photo} authors.photos.destroy route('authors.photos.destroy')

List of exclusions

By publishing a configuration file with the artisan command, you can explicitly specify a mask of route names that do not need to be translated:

php artisan vendor:publish --provider="DragonCode\LaravelRouteNames\ServiceProvider"

Exceptions

app('router')
    ->get('pages', [IndexController::class, 'index'])
    ->name('my_pages');

return route('my_pages');
//  \Symfony\Component\Routing\Exception\RouteNotFoundException
//  Route [my_pages] not defined.

return route('pages.index');
// Returns the result of executing the `IndexController@index` method.

Result

app('router')
    ->name('pages.')
    ->prefix('pages')
    ->group(function () {
        app('router')->get('/', [Controller::class, 'index']);
        app('router')->post('/', [Controller::class, 'store']);
        app('router')->get('{page}', [Controller::class, 'show']);
        app('router')->delete('{page}', [Controller::class, 'destroy']);
    });

Before:

GET     /pages         pages.
POST    /pages         pages.
GET     /pages/{page}  pages.
DELETE  /pages/{page}  pages.

After:

GET     /pages         pages.index
POST    /pages         pages.store
GET     /pages/{page}  pages.show
DELETE  /pages/{page}  pages.destroy

License

This package is licensed under the MIT License.

dragon-code/laravel-route-names 适用场景与选型建议

dragon-code/laravel-route-names 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.23k 次下载、GitHub Stars 达 25, 最近一次更新时间为 2022 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dragon-code/laravel-route-names 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 9.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 25
  • 点击次数: 16
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-05