mertyildiran/laravel-advanced-route 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mertyildiran/laravel-advanced-route

Composer 安装命令:

composer require mertyildiran/laravel-advanced-route

包简介

Advanced route class for Laravel - restoring implicit controllers to the framework.

README 文档

README

An advanced route for Laravel 5.3, 5.4, 5.5 and 5.6 to support controllers

Background

In Laravel 5.3 the advanced functionality Route::controller was removed. This class fixes this shortcoming.

Reason

The default router is sufficient for small projects. Once the project starts to grow, placing all possible route definitions in the router file start to become harder to understand and follow. Quite often the router file becomes so messy, that the developer is afraid to modify/remove routes (even if these might be unused) in order to not break the application unexpectedly.

The AdvancedRoute::controller gives the control to the controller itself, and makes each controller responsible for its own routing (destiny).

Specifying the controller methods with get/post/any prefixes improves readability, and allows to easily understand what HTTP method is being used to call the functionality just by viewing the method.

Does your router file not fit the screen and you have to scroll to see all routes? Have you split your routes in separate router files, and included these in one router files? Do you not feel comfortable removing routes, as these might be used somewhere? Do you use names to "name" your routes? Then its time to think outside the box and go advanced.

How it works

The advanced route allows you to easily define a single route to handle every action in a controller class. First, define the route using the AdvancedRoute::controller method. The controller method accepts two arguments. The first is the base URI the controller handles, while the second is the class name of the controller. Next, just add methods to your controller. The method names should begin with the HTTP verb they respond to followed by the title case version of the URI.

<?php

namespace App\Http\Controllers;

class UserController extends Controller {
    /**
     * Responds to any (GET,POST, etc) request to /users
     */
    public function anyIndex() {
        //
    }

    /**
     * Responds to requests to GET /users/show/1
     */
    public function getShow($id) {
        //
    }

    /**
     * Responds to requests to GET /users/admin-profile
     */
    public function getAdminProfile() {
        //
    }

    /**
     * Responds to requests to POST /users/profile
     */
    public function postProfile() {
        //
    }
}

Installation

a) via composer (recommended)

composer require lesichkovm/laravel-advanced-route

b) manually

Add the following to your composer file:

   "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/lesichkovm/laravel-advanced-route.git"
        }
    ],
    "require": {
        "lesichkovm/laravel-advanced-route": "dev-master"
    },

Usage

Add the following line to where you want your controller to be mapped:

AdvancedRoute::controller('/{YOUR PATH}', '{YOUR CONTROLLER FULL NAME}');

Full Example:

Route::group(['prefix' => '/', 'middleware' => []], function () {
    AdvancedRoute::controller('/auth', 'AuthController');
    AdvancedRoute::controller('/cms', 'CmsController');
    AdvancedRoute::controller('/shop', 'ShopController');
    Route::any('/', 'WebsiteController@anyIndex');
});

Multiple controllers mapping:

AdvancedRoute::controllers([
    '/auth' => 'AuthController',
    '/cms' => 'CmsController',
    '/shop' => 'ShopController',
]);

Missing method:

If you have a controller with a few predefined routes, you can add the missingMethod() to handle all undefined sub-paths for that controller's path.

class WikiController extends Controller
{
    public function getIndex() { /* show main page or list of content */ }
    public function getCreate() { /* a page to add a new wiki-page */ }
    public function postCreate() { /* add a new wiki-page */ }
    public function missingMethod() { /* do anything elselook up the path in the wiki-database */ }
}

Acknowledgements

Laravel Advanced Route is only possible thanks to all the awesome contributors!

Alternatives

Is Laravel too bloated and slow, yes tell me about it? You want to go down the pure PHP route? Well, here are some notable packages, which will allow you to keep the niceties of the Larael routing:

https://github.com/mrjgreen/phroute

mertyildiran/laravel-advanced-route 适用场景与选型建议

mertyildiran/laravel-advanced-route 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 27
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2019-08-25