PHP code example of haganjones / laravel-observe-properties

1. Go to this page and download the library: Download haganjones/laravel-observe-properties 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/ */

    

haganjones / laravel-observe-properties example snippets



 
namespace App\Observers;
 
use HaganJones\LaravelObserveProperties\ObserveProperties;
 
class UserObserver
{
    use ObserveProperties; 
}

// Inside UserObserver Class
 
public function emailUpdated(User $user, $oldValue, $newValue)
{
    $format = 'User %d changed their email from %s to %s';
    Log::info(sprintf($format, $user->id, $oldValue, $newValue));
    // User 1 changed their email from [email protected] to [email protected]
}


 
namespace App\Observers;
 
use HaganJones\LaravelObserveProperties\ObserveProperties;
use App\User;
 
class UserObserver
{
    use ObserveProperties {
        updating as updatingProperties;
        //add in other method aliases here.
    }
    
    public function updating(User $user)
    {
        //Do things with $user
        
        return $this->updatingProperties($user);
    }
    
    public function firstNameUpdating(User $user, $oldValue, $newValue)
    {
        //$user->first_name was just updated.
    }
}