PHPackages                             juniorfontenele/laravel-events - 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. juniorfontenele/laravel-events

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

juniorfontenele/laravel-events
==============================

This is my package laravel-events

03[5 PRs](https://github.com/juniorfontenele/laravel-events/pulls)PHPCI passing

Since Jun 17Pushed 4mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (7)Used By (0)

Laravel Events
==============

[](#laravel-events)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bc242e8e7e9034e2fd783fd1e7558144a3f0ce04174bab20e01ff17890685627/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a756e696f72666f6e74656e656c652f6c61726176656c2d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juniorfontenele/laravel-events)[![Tests](https://camo.githubusercontent.com/035563a06bd88d603622e4af3d91f0308e5a26871910fed4dd16ce4fbec19fc8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a756e696f72666f6e74656e656c652f6c61726176656c2d6576656e74732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/juniorfontenele/laravel-events/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/cdf77201292f56d2dbbcaf4da81c56ae81721248876684122012cf9f4a2ec0ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756e696f72666f6e74656e656c652f6c61726176656c2d6576656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juniorfontenele/laravel-events)

Laravel Events is a package designed to simplify event handling in Laravel applications. It provides tools for logging, rate-limiting, and syncing events between files and the database.

Features
--------

[](#features)

- Log events to files or the database.
- Rate-limit event handling to prevent abuse.
- Sync events between files and the database.
- Support for custom event types and levels.
- Automatically generates unique and sequential identifiers for events.
- Includes database migrations for event storage.

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

[](#installation)

You can install the package via composer:

```
composer require juniorfontenele/laravel-events
```

After installation, run the migrations to set up the necessary database tables:

```
php artisan migrate
```

If you want to customize the migrations, you can publish them using the following command:

```
php artisan vendor:publish --tag=laravel-events-migrations
```

The migrations will be published to the `database/migrations` directory, where you can modify them as needed.

Configuration
-------------

[](#configuration)

Publish the configuration file to customize the package behavior:

```
php artisan vendor:publish --tag=laravel-events-config
```

The configuration file will be published to `config/events.php`. You can customize settings such as rate-limiting and default event behavior.

Usage
-----

[](#usage)

### Creating Events

[](#creating-events)

Create events using the Artisan command provided by the package:

```
php artisan make:event EventName
```

This command will generate a new event file in the appropriate directory with a unique and sequential identifier for traceability. The generated file will include all necessary properties, such as `id`, `name`, `type`, `level`, and `description`.

Example of a generated event file:

```
use JuniorFontenele\LaravelEvents\BaseEvent;
use JuniorFontenele\LaravelEvents\Enums\EventType;
use JuniorFontenele\LaravelEvents\Enums\EventLevel;

class UserRegistered extends BaseEvent
{
    public int $id = 1; // Automatically generated
    public string $name = 'User Registered';
    public EventType $type = EventType::USER;
    public EventLevel $level = EventLevel::INFO;
    public string $description = 'Triggered when a user registers.';
    public bool $shouldLog = true;
    public bool $shouldWriteToDatabase = true;
}
```

### Logging Events

[](#logging-events)

Use the `WriteEventsToLog` listener to log events to the Laravel log system. Ensure your event implements the `shouldLog` method.

### Writing Events to the Database

[](#writing-events-to-the-database)

Use the `WriteEventsToDatabase` listener to persist events to the database. Ensure your event implements the `shouldWriteToDatabase` method.

### Rate Limiting

[](#rate-limiting)

The `HasRateLimiter` trait provides methods to limit the number of times an event can be handled within a specific time frame. Configure rate-limiting in `config/events.php`.

### Commands

[](#commands)

The package provides several Artisan commands:

#### Sync Events from Files

[](#sync-events-from-files)

```
php artisan events:sync-from-file
```

This command updates the database with the information from the event files located in the `App\Events` directory. It ensures that all events defined in files are properly registered in the database. This is useful when new events are added or existing ones are modified in the codebase.

#### Sync Events from Database

[](#sync-events-from-database)

```
php artisan events:sync-from-db
```

This command generates event files for events that exist in the database but are missing in the `App\Events` directory. It ensures that all events in the database have corresponding files in the codebase. This is useful for restoring missing event files.

#### Clear Old Events

[](#clear-old-events)

```
php artisan events:clear-old
```

This command deletes events older than a specified number of days (default is 180 days). The maximum age can be configured in `config/events.php` under the `max_days` setting. This command can be added to the Laravel scheduler to automatically clean up old event records:

```
$schedule->command('events:clear-old')->daily();
```

#### Reorder Event IDs

[](#reorder-event-ids)

```
php artisan events:reorder-ids
```

This command reorders the event IDs in the database to ensure they are sequential. This is useful when events have been deleted, and you want to maintain a clean, sequential order of IDs. Use the `--force` option to skip confirmation:

```
php artisan events:reorder-ids --force
```

#### List Events

[](#list-events)

```
php artisan events:list
```

List all events stored in the database.

Testing
-------

[](#testing)

Run the tests with:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Junior Fontenele](https://github.com/juniorfontenele)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance50

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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://avatars.githubusercontent.com/u/3694405?v=4)[Junior Fontenele](/maintainers/juniorfontenele)[@juniorfontenele](https://github.com/juniorfontenele)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")[![juniorfontenele](https://avatars.githubusercontent.com/u/3694405?v=4)](https://github.com/juniorfontenele "juniorfontenele (1 commits)")

### Embed Badge

![Health badge](/badges/juniorfontenele-laravel-events/health.svg)

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

PHPackages © 2026

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