thejawker/laravel-route-module-macro 问题修复 & 功能扩展

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

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

thejawker/laravel-route-module-macro

Composer 安装命令:

composer require thejawker/laravel-route-module-macro

包简介

Exposes a module concept to enforce a CRUD and Restful way of routing and naming convention.

README 文档

README

Latest Version on Packagist Build Status Quality Score Total Downloads

This package works with Laravel 5.5. It is very much inspired by the great Freek van der Herten with their Blender Package, where he has a Macro for a module. This really resonates with the CRUD/Restful approach on routing.

Installation

Require the package from Composer:

composer require thejawker/laravel-route-module-macro

As of Laravel 5.5 it will magically register the package.

Usage

You can add Route::module('name', ['only'](optional), ['options](optional)) in any of your routes files. The second parameter will allow you to only use specific actions, and the third being general options. Refer to the Laravel docs for those.

Examples:

Full Resource

routes/api.php

Route::module('posts');
$ php artisan route:list
+-----------+-----------------------------------------+---------------+---------------------------------------------------------------------------+
| Method    | URI                                     | Name          | Action                                                                    |
+-----------+-----------------------------------------+---------------+---------------------------------------------------------------------------+
| POST      | api/posts                               | posts.store   | App\Http\Controllers\PostsController@store                                |
| GET|HEAD  | api/posts                               | posts.index   | App\Http\Controllers\PostsController@index                                |
| GET|HEAD  | api/posts/create                        | posts.create  | App\Http\Controllers\PostsController@create                               |
| DELETE    | api/posts/{post}                        | posts.destroy | App\Http\Controllers\PostsController@destroy                              |
| PUT|PATCH | api/posts/{post}                        | posts.update  | App\Http\Controllers\PostsController@update                               |
| GET|HEAD  | api/posts/{post}                        | posts.show    | App\Http\Controllers\PostsController@show                                 |
| GET|HEAD  | api/posts/{post}/edit                   | posts.edit    | App\Http\Controllers\PostsController@edit                                 |
+-----------+-----------------------------------------+---------------+---------------------------------------------------------------------------+

Only Resource

routes/api.php

Route::module('posts', ['store']);
$ php artisan route:list
+-----------+-----------------------------------------+---------------+----------------------------------------------------------------------------+
| Method    | URI                                     | Name          | Action                                                                     |
+-----------+-----------------------------------------+---------------+----------------------------------------------------------------------------+
| POST      | api/posts                               | posts.store   | App\Http\Controllers\PostsController@store                                 |
+-----------+-----------------------------------------+---------------+----------------------------------------------------------------------------+

Nested Resources

This will enforce you to write Controllers that make sense. A nested users.posts will require you to create a UserPostsController with the required actions. routes/api.php

Route::module('users.posts');
$ php artisan route:list
+-----------+-----------------------------------------+---------------------+----------------------------------------------------------------------------+
| Method    | URI                                     | Name                | Action                                                                     |
+-----------+-----------------------------------------+---------------------+----------------------------------------------------------------------------+
| POST      | api/users/{user}/posts                  | users.posts.store   | App\Http\Controllers\UserPostsController@store                             |
| GET|HEAD  | api/users/{user}/posts                  | users.posts.index   | App\Http\Controllers\UserPostsController@index                             |
| GET|HEAD  | api/users/{user}/posts/create           | users.posts.create  | App\Http\Controllers\UserPostsController@create                            |
| DELETE    | api/users/{user}/posts/{post}           | users.posts.destroy | App\Http\Controllers\UserPostsController@destroy                           |
| PUT|PATCH | api/users/{user}/posts/{post}           | users.posts.update  | App\Http\Controllers\UserPostsController@update                            |
| GET|HEAD  | api/users/{user}/posts/{post}           | users.posts.show    | App\Http\Controllers\UserPostsController@show                              |
| GET|HEAD  | api/users/{user}/posts/{post}/edit      | users.posts.edit    | App\Http\Controllers\UserPostsController@edit                              |
+-----------+-----------------------------------------+---------------------+----------------------------------------------------------------------------+

Test

This package definitely needs some extensive testing.

composer test

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固