定制 ricventu/laravel-route-maze 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ricventu/laravel-route-maze

最新稳定版本:v1.1.4

Composer 安装命令:

composer require ricventu/laravel-route-maze

包简介

A quick and easy way to create the routes is to take advantage of the convention over configuration

README 文档

README

Warning

This project is archived and no longer maintained.

Please use spatie/laravel-route-discovery instead, which I have contributed to and provides the same convention-over-configuration approach to route generation.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A quick and easy way to auto generate routes, is to take advantage of the convention over configuration and PHP attributes.
This means that routes are automatically generated based on the directory structure of the controllers and the methods attributes.
In this way, you don't have to manually write the routes in the web.php or api.php file, but just follow some rules of file naming and organization.
Route groups are base on subdirectories of the controllers.

Let's see how to do it with a practical example.

Controller: App/Http/Controllers/SomeCategory/ProductsController.php

class ProductsController
{
    // index and __invoke defaults to GET
    public function index() {...}
    #[Get]
    public function show($id) {...}
    #[Post]
    public function store(Request $request) {...}
    #[Patch]
    public function update($id, Request $request) {...}
    #[Delete]
    public function destroy($id) {...}
}

To get routes simpli add the the following line to routes/web.php

    Route::maze(app_path('Http/Controllers'), 'App\\Http\\Controllers');

The generated routes are:

    Route::get('/some-category/products', 'SomeCategory\ProductsController@index')->name('some-category.products');
    Route::get('/some-category/products/show/{id}', 'SomeCategory\ProductsController@show')->name('some-category.products.show');
    Route::post('/some-category/products/store', 'SomeCategory\ProductsController@store')->name('some-category.products.store');
    Route::Patch('/some-category/products/update/{id}', 'SomeCategory\ProductsController@update')->name('some-category.products.update');
    Route::delete('/some-category/products/destroy/{id}', 'SomeCategory\ProductsController@destroy')->name('some-category.products.destroy');

Parameters in path

Parameters can be specified in the path naming the directory with _param-name_.

Http/Controllers/_param1_/ItemsController.php

class ItemsController
{
    #[Get]
    public function get($id) {...}
}

becomes

    Route::get('/{param1}/items/get/{id}', 'ItemsController@get')->name('items.get');

Middleware

You can specify middleware group by adding a file named middleware.php in the controller directory.

return [
    'auth',
];

Naming conventions

Uri and route name are composed of directories name, first part of the controller name (before Controller) and method name, all in kebab-case.

examples:

Controller name Method name Route name Route path
SomeProductController showItem($id) some.product.show-item /some-product/show-item/{id}
SomeProductController storeItem some.product.store-item /some-product/store-item
SomeProductController updateItem($id) some.product.update-item /some-product/update-item/{id}
SomeProductController destroyItem($id) some.product.destroy-item /some-product/destroy-item/{id}

Disable discover for a Controller

To disable route discover for a specified crontroller, add static method mazeDisabled that returns true

In path configuration

If in the path is present a file named maze.php, it will be used to configure the route group.

return [
];
Key Description Default
ignore_path_name Ignore path and name in route false
disabled Disable discovering of the entire path
## Installation

You can install the package via composer:

```bash
composer require ricventu/laravel-route-maze

Usage

    Route::maze(app_path('Http/Controllers'), 'App\\Http\\Controllers');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Performance note

In production deployment, it's recommended to cache route discovering using Laravel route:cache built in command

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固