Laravel Eloquent Observable

Overview

Laravel Eloquent Observable

Latest Version Software License Build Status Total Downloads

Register Eloquent model event listeners just-in-time directly from the model.

Using Observers can introduce a (significant) overhead on the application since they are usually registered in a service provider which results in every model in your application with a observer is "booted" a startup of the application even though the model is never touched in the request. This package aims to reduce that overhead by connecting listeners just-in-time whenever the Eloquent model is booted (first used) in the request. The event callbacks are also defined on the model itself keeping the code cleaner, althought this is my preference of course and if you disagree this might not be the package for you.

Installation

composer require stayallive/laravel-eloquent-observable

Usage

Adding the Observable trait will ensure that the observable events are connected to the event handlers defined on the model.



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Stayallive\Laravel\Eloquent\Observable\Observable;

class SomeModel extends Model
{
    use Observable;

    // Event handlers are defined by `onEventName` where `EventName` is any valid Eloquent event (or custom event)
    // See a full list of Eloquent events: https://laravel.com/docs/9.x/eloquent#events
    public static function onSaving(self $model): void
    {
        // For example:
        $model->slug = str_slug($model->title);
    }
}

Security Vulnerabilities

If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at [email protected]. All security vulnerabilities will be swiftly addressed.

License

This package is open-sourced software licensed under the MIT license.

You might also like...
A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache.

Laravel OTP Introduction A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache. The ca

 Provides a Eloquent query builder for Laravel or Lumen
Provides a Eloquent query builder for Laravel or Lumen

This package provides an advanced filter for Laravel or Lumen model based on incoming requets.

Curso Laravel Eloquent ORM

Curso Laravel Eloquent ORM

Use eloquent joins in Laravel way, with composite key support.

Eloquent Power Joins with Compoships Support This package is an Eloquent Power Joins extension to support Compoships. You can now use joins in Laravel

Tag support for Laravel Eloquent models - Taggable Trait

Laravel Taggable Trait This package is not meant to handle javascript or html in any way. This package handles database storage and read/writes only.

Laravel basic Functions, eloquent cruds, query filters, constants

Emmanuelpcg laravel-basics Description Package with basic starter features for Laravel. Install If Builder Constants Install composer require emmanuel

An extended laravel eloquent WHERE method to work with sql LIKE operator.

Laravel Eloquent WhereLike An extended laravel eloquent WHERE method to work with sql LIKE operator. Inspiration The idea of this package comes from o

Laravel package for creating Word documents with Eloquent ORM dependencies.

Laravel Eloquent Word This package provides an elegant way to generate Word documents with Eloquent Models. Uses PHPOffice/PHPWord package to generate

A Single Table Inheritance Trait for Eloquent/Laravel

Single Table Inheritance Credit This code is a fork of Nanigans/single-table-inheritance. I've only updated it to work with Laravel 5 Single Table Inh

Releases(v1.0.1)
Owner
Alex Bouma
PHP artisan, full stack dev and server wrangler | Founder @simulise | Building chief.app @irongate | Laravel / PHP SDK dev @getsentry
Alex Bouma
This Laravel package merges staudenmeir/eloquent-param-limit-fix and staudenmeir/laravel-adjacency-list to allow them being used in the same model.

This Laravel package merges staudenmeir/eloquent-param-limit-fix and staudenmeir/laravel-adjacency-list to allow them being used in the same model.

Jonas Staudenmeir 5 Jan 6, 2023
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Jan 7, 2023
Easy creation of slugs for your Eloquent models in Laravel

Eloquent-Sluggable Easy creation of slugs for your Eloquent models in Laravel. NOTE: These instructions are for the latest version of Laravel. If you

Colin Viebrock 3.6k Dec 30, 2022
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 955 Dec 25, 2022
Laravel Ban simplify blocking and banning Eloquent models.

Laravel Ban Introduction Laravel Ban simplify management of Eloquent model's ban. Make any model bannable in a minutes! Use case is not limited to Use

cybercog 879 Dec 30, 2022
cybercog 996 Dec 28, 2022
Orbit is a flat-file driver for Laravel Eloquent

Orbit is a flat-file driver for Laravel Eloquent. It allows you to replace your generic database with real files that you can manipulate using the methods you're familiar with.

Ryan Chandler 664 Dec 30, 2022
Collection of the Laravel/Eloquent Model classes that allows you to get data directly from a Magento 2 database.

Laragento LAravel MAgento Micro services Magento 2 has legacy code based on abandoned Zend Framework 1 with really ugly ORM on top of outdated Zend_DB

Egor Shitikov 87 Nov 26, 2022
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Mouad ZIANI 59 Sep 25, 2022
Laravel Quran is static Eloquent model for Quran.

Laravel Quran بِسْمِ ٱللّٰهِ الرَّحْمٰنِ الرَّحِيْمِ Laravel Quran is static Eloquent model for Quran. The Quran has never changed and never will, bec

Devtical 13 Aug 17, 2022