gregs/attribute-router 问题修复 & 功能扩展

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

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

gregs/attribute-router

Composer 安装命令:

composer require gregs/attribute-router

包简介

Attribute based routing for laravel.

README 文档

README

This library is under active development and the public api is likely to change without warning

Usage

Attribute based routing can be activated for a namespace
by adding the following to your routes/api.php or routes/web.php file:

<?php

use Gregs\AttributeRouter\AttributeRouter;

AttributeRouter::namespace('App\Http\Your\Namespace');

Routes can then be defined like this:

<?php

namespace App\Http\Your\Namespace;

use Gregs\AttributeRouter\Attributes\Controller;
use Gregs\AttributeRouter\Attributes\Get;

#[Controller]
class YourController
{
     #[Get('uri')]
    public function index()
    {
      return;
    }
}

⚠️ If the controller attribute is not present the #[Get('uri')] attribute wont have any effect

This will result in the following routing setup:

Route::controller(YourController::class)->group(function() {
  Route::get('uri','index');
});

Prefixes and middlewares can be used on a controller or method level:

<?php

namespace App\Http\Your\Namespace;

use Gregs\AttributeRouter\Attributes\Controller;
use Gregs\AttributeRouter\Attributes\Get;
use Gregs\AttributeRouter\Attributes\Post;
use Gregs\AttributeRouter\Attributes\Patch;
use Gregs\AttributeRouter\Attributes\Prefix;
use Gregs\AttributeRouter\Attributes\Middleware;

#[Controller]
#[Prefix('v1')]
class YourController
{
    #[Get('uri')]
    #[Prefix('entity')]
    public function index()
    {
      return;
    }

    #[Post('uri')]
    #[Prefix('entity')]
    #[Middleware('auth-sanctum')]
    public function post()
    {
      return;
    }

    #[Patch('uri')]
    #[Prefix('entity')]
    #[Middleware('auth-sanctum')]
    public function patch()
    {
      return;
    }
}

This will result in the following routing setup:

Route::prefix('v1')->group(function() {
  Route::controller('YourController::class')->group(function() {
    Route::prefix('entity')->group(function() {
      Route::get('uri','index');
      Route::middleware('auth-sanctum')->group(function() {
          Route::post('uri','post');
          Route::patch('uri','patch');
      });
    });
  });
});

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固