PHPackages                             proai/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. proai/lumen-annotations

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

proai/lumen-annotations
=======================

Route and event binding annotations for Laravel Lumen

1.0.2(10y ago)1012.4k↓50%3[3 PRs](https://github.com/ProAI/lumen-annotations/pulls)MITPHPPHP &gt;=5.5.9

Since Nov 27Pushed 6y ago2 watchersCompare

[ Source](https://github.com/ProAI/lumen-annotations)[ Packagist](https://packagist.org/packages/proai/lumen-annotations)[ Docs](http://github.com/proai/lumen-annotations)[ RSS](/packages/proai-lumen-annotations/feed)WikiDiscussions master Synced 1mo ago

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

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

[](#lumen-annotations)

[![Latest Stable Version](https://camo.githubusercontent.com/55377e90e761bed943b6cf1908bb7d439b49ea5fbd90a46a73d9a0b97db2fc62/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f6c756d656e2d616e6e6f746174696f6e732f762f737461626c65)](https://packagist.org/packages/proai/lumen-annotations) [![Total Downloads](https://camo.githubusercontent.com/8353fb27a9a13ed5f8853e7b7d5761a7ab9446cde82864cf5861e786df58151c/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f6c756d656e2d616e6e6f746174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/proai/lumen-annotations) [![Latest Unstable Version](https://camo.githubusercontent.com/3a0e4a82e1c523007fbced3063bde763e416c1885fe5b16fc31f0e86a6b55f6a/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f6c756d656e2d616e6e6f746174696f6e732f762f756e737461626c65)](https://packagist.org/packages/proai/lumen-annotations) [![License](https://camo.githubusercontent.com/3ed865c68f211f5794e0ae3ca656ab07ce4b67eeae4a0610d04e5d353fe785aa/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f6c756d656e2d616e6e6f746174696f6e732f6c6963656e7365)](https://packagist.org/packages/proai/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 add the package to your `composer.json` file:

```
"proai/lumen-annotations": "~1.0"

```

Then you have to run `composer update` to install the package. Once this is completed, you have to add the service provider in `bootstrap/app.php`:

```
$app->register(ProAI\Annotations\AnnotationsServiceProvider::class);

```

Copy `config/annotations.php` from this package to your configuration directory to use a custom configuration file.

##### Include generated routes

[](#include-generated-routes)

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

```
require __DIR__.'/../storage/framework/routes.php';
```

##### Include generated event bindings

[](#include-generated-event-bindings)

After you have executed `php artisan event:scan` (see below), you have to add the service provider to the providers array in `config/app.php`:

```
'ProAI\Annotations\EventServiceProvider'

```

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)

```
