PHP code example of stayallive / laravel-eloquent-observable

1. Go to this page and download the library: Download stayallive/laravel-eloquent-observable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stayallive / laravel-eloquent-observable example snippets




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);
    }
}