PHPackages                             deva7mad/lumen-annotations - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. deva7mad/lumen-annotations

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

deva7mad/lumen-annotations
==========================

Laravel Lumen route and event binding annotations generate

1.1(7y ago)1213MITPHPPHP &gt;=5.5.9

Since Oct 6Pushed 6y ago2 watchersCompare

[ Source](https://github.com/deva7mad/lumen-annotations)[ Packagist](https://packagist.org/packages/deva7mad/lumen-annotations)[ RSS](/packages/deva7mad-lumen-annotations/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Lumen Annotations
=================

[](#lumen-annotations)

[![Latest Stable Version](https://camo.githubusercontent.com/2aaadc8861a98692ecec4667223640873bde48790c88e6957c48247d14ed45fd/68747470733a2f2f706f7365722e707567782e6f72672f64657661376d61642f6c756d656e2d616e6e6f746174696f6e732f762f737461626c65)](https://packagist.org/packages/deva7mad/lumen-annotations) [![Total Downloads](https://camo.githubusercontent.com/12303a9b0bb29bc1f804621316eed9aded0f82ed9b8f4dd02f5fd951e59836c5/68747470733a2f2f706f7365722e707567782e6f72672f64657661376d61642f6c756d656e2d616e6e6f746174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/deva7mad/lumen-annotations) [![Latest Unstable Version](https://camo.githubusercontent.com/90781c31ba2f6235aefbdb4865bf97094a10300d182983703bb6e71794dde48d/68747470733a2f2f706f7365722e707567782e6f72672f64657661376d61642f6c756d656e2d616e6e6f746174696f6e732f762f756e737461626c65)](https://packagist.org/packages/deva7mad/lumen-annotations) [![License](https://camo.githubusercontent.com/d80dcbcb88a3c867153577d819758d52ad3fcd1984f8601c276621324a9ae861/68747470733a2f2f706f7365722e707567782e6f72672f64657661376d61642f6c756d656e2d616e6e6f746174696f6e732f6c6963656e7365)](https://packagist.org/packages/deva7mad/lumen-annotations)

This package enables annotations in Laravel Lumen to define routes and event bindings.

Installation
------------

[](#installation)

Lumen Annotations is distributed as a composer package. So you first have to run the following command

```
composer require deva7mad/lumen-annotations

```

After that copy `config/annotations.php` from this package to your configuration directory.

Finally: Add this lines to `bootstrap/app.php` file:

```
$app->configure('annotations');
$app->register(DevA7mad\Annotations\AnnotationsServiceProvider::class);

```

##### Include generated routes

[](#include-generated-routes)

Once you have run `php artisan route:scan` (NOTE: see below Examples), you have to include the generated `generated.php` file in your `bootstrap/app.php` file:

```
require __DIR__.'/../routes/generated.php';
```

Usage
-----

[](#usage)

By using annotations you can define your routes directly in your controller classes and your event bindings directly in your event handlers (see examples for usage of annotations).

##### Class Annotations

[](#class-annotations)

For routes:

AnnotationDescription`@Controller`This annotation must be set to indicate that the class is a controller class. Optional parameters `prefix` and `middleware`.`@Resource`First parameter is resource name. Optional parameters `only` and `except`.`@Middleware`First parameter is middleware name.For events:

AnnotationDescription`@Hears`This annotation binds an event handler class to an event.##### Method Annotations

[](#method-annotations)

For routes:

AnnotationDescription`@Get`,
`@Post`,
`@Options`,
`@Put`,
`@Patch`,
`@Delete`,
`@Any`First parameter is route url. Optional parameters `as` and `middleware`.`@Middleware`First parameter is middleware name.### Commands

[](#commands)

After you have defined the routes and event bindings via annotations, you have to run the scan command:

- Use `php artisan route:scan` to register all routes.
- Use `php artisan route:clear` to clear the registered routes.
- Use `php artisan event:scan` to register all event bindings.
- Use `php artisan event:clear` to clear the registered events.

### Examples

[](#examples)

##### Example #1

[](#example-1)

```
