PHPackages                             lynxcat/laravel-annotation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lynxcat/laravel-annotation

ActiveLibrary

lynxcat/laravel-annotation
==========================

laravel annotation

03PHP

Since Apr 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lynxcat/laravel-annotation)[ Packagist](https://packagist.org/packages/lynxcat/laravel-annotation)[ RSS](/packages/lynxcat-laravel-annotation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-annotation
==================

[](#laravel-annotation)

最近在laravel项目中，遇到了显式路由和隐式之争。 显式路由太杂乱，要么文件里面写很多条路由，要么分成很多文件，不是很爽。而隐式路由，因为需要实现一套自己项目的内部逻辑，增加一定的上手成本，还有可能导致框架本身的route:cache使用不了

为了能够更好的解决路由这个问题，尝试用reflection机制模拟了一个sping的注解写法，一方面不用谢配置文件，第二方面可以很好的兼容route:cache，开发运行两不误

暂时实现了对类的@RequestMapping(value="user", prefix="system", middleware="auth")功能，参数均为可选，如果只有一个value 可以直接用 @RequestMapping("user")

对于函数实现了 @PostMapping, @GetMapping, @PutMapping, @AnyMapping, @PatchMapping, @DeleteMapping, @OptionsMapping， 参数与@RequestMapping一致, 不同点在于value为必填，不写会异常

支持@GetMapping("/detail/{id}") 这种动态参数的模式，目前尚不支持domain resource, where, namespace, only 等功能，后面如果项目有需要的话进行更新

\##安装使用

\###Route

Step 1.下载源码

```
    composer require lynxcat/laravel-annotation
```

Step 2.在控制器中使用注解

```

    /**
     * Class UserController
     * @package App\Http\Controllers
     * @RequestMapping("users")
     */
    class UserController extends Controller
    {

        /**
         * 用户列表
         * @GetMapping(value="/list", middleware={"auth"})
         */
        public function index()
        {
            return "hello, user list";
        }

        /**
         * 用户编辑
         *
         * @GetMapping("/edit/{id}")
         * @PostMapping("/eidt/{id}", middleware={"auth:eidt-user"})
         */
        public function eidt(int $id) {

        }

    }
```

浏览器访问 http://your\_host/users/list 就可以看到结果了

\###Service

Step 1.在类中加上注解

```
/**
 * Class UserServiceImpl
 * @package App\Services
 *
 * @Service
 */
class UserServiceImpl implements UserInterface {

}
```

Step 2.可以直接使用

```
use App\Contracts\UserInterface as User;
use Illuminate\Http\Request;

/**
 * Class UserController
 * @package App\Http\Controllers
 * @RequestMapping("users")
 */
class UserController extends Controller
{
    protected $user;
    protected $request;

    public function __construct(Request $request, User $user)
    {
        $this->request = $request;
        $this->user = $user;
    }
}
```

另外扩展包自带了两个命令

```
    php artisan annotation:cache #生成缓存文件
    php artisan annotation:clear #清除缓存文件
```

缓存文件放在 /vendor/lynxcat/laravel-annotation/src/Cache/中，可以用于对比生成的route以及service是否正确。

生产环境建议使用 php artisan annotation:cache; php artisan route:cache 可以提升文件读取效率

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e18f1b6b5c17a9df481f491fa8ebaafbe968335a26641a5fbe1e6e2e943d0e1f?d=identicon)[lynxcat](/maintainers/lynxcat)

---

Top Contributors

[![lynxcat](https://avatars.githubusercontent.com/u/2222701?v=4)](https://github.com/lynxcat "lynxcat (20 commits)")

### Embed Badge

![Health badge](/badges/lynxcat-laravel-annotation/health.svg)

```
[![Health](https://phpackages.com/badges/lynxcat-laravel-annotation/health.svg)](https://phpackages.com/packages/lynxcat-laravel-annotation)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
