Download the PHP package plank/before-and-after-model-events without Composer

On this page you can find all versions of the php package plank/before-and-after-model-events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package before-and-after-model-events

PHP Version Support PHP Version Support GitHub Workflow Status

Before and After Model Events

This package adds before and after events for every Laravel Eloquent model event, giving you complete control over your model's lifecycle. It works with all standard Laravel model events (creating, created, updating, updated, deleting, deleted, etc.) and any custom events you define.

Features

Event Flow

When working with model events, this package ensures the following execution order:

For standard Laravel events (like saving a model):

  1. beforeCreating โ†’ creating โ†’ afterCreating
  2. beforeSaving โ†’ saving โ†’ afterSaving
  3. beforeCreated โ†’ created โ†’ afterCreated
  4. beforeSaved โ†’ saved โ†’ afterSaved

For custom events (like publishing a post):

  1. beforePublishing โ†’ publishing โ†’ afterPublishing

Installation

You can install the package via composer:

Usage

Simply add the BeforeAndAfterEvents trait to any Eloquent model:

Basic Usage

1. Add the Trait

Add the BeforeAndAfterEvents trait to any Eloquent model:

2. Register Event Listeners

Use the static methods to register before and after event listeners:

Advanced Features

Event Prevention

Before events can prevent the main event (and subsequent after events) from firing by returning false:

Custom Events

The package works seamlessly with any custom events you fire on your models:

Multiple Listeners

You can register multiple listeners for the same event:

Soft Deletes Support

The package works perfectly with Laravel's soft deletes:

Integration with Existing Event Systems

The package works alongside existing Laravel event dispatchers and observers:

Event Reference

Standard Laravel Events

All standard Laravel model events are supported:

Custom Events

Any event name can be used - the package will automatically register the before/after variants:

How It Works

The package uses a simple but powerful approach:

  1. Dynamic Event Registration: When you call beforeEvent() or afterEvent(), the package registers the base event (e.g., publishing) in a static registry and adds the before/after variants (beforePublishing, afterPublishing) to the model's observable events.

  2. Event Interception: The trait overrides the fireModelEvent() method to intercept all model events and fire the before/after events at the appropriate times.

  3. Minimal Overhead: Events are only registered when actually used, and the trait adds minimal performance overhead to your models.

Requirements

Testing

The package includes a comprehensive test suite with 22 tests covering:

Run the tests:

Run tests with coverage:

Run static analysis:

 

Credits

 

License

The MIT License (MIT). Please see License File for more information.

 

Security Vulnerabilities

If you discover a security vulnerability within Before and After Model Events, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

 

Check Us Out!

 

Plank focuses on impactful solutions that deliver engaging experiences to our clients and their users. We're committed to innovation, inclusivity, and sustainability in the digital space. Learn more about our mission to improve the web.


All versions of before-and-after-model-events with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package plank/before-and-after-model-events contains the following files

Loading the files please wait ...