PHP code example of rain-plus / eloquent-inject-attribute

1. Go to this page and download the library: Download rain-plus/eloquent-inject-attribute 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/ */

    

rain-plus / eloquent-inject-attribute example snippets


(new InjectModelAttribute(User::class))
    ->attribute('money', function(User $user) use ($economy) {
        return $economy->getMoney($user);
    }, function (User $user, $name, $value) use ($economy) {
        $originalMoney = $economy->getMoney($user);
        $delta = $value - $originalMoney;
        $economy->addMoney($user, $delta);
    });

// Then you can do...
$money = $user->money;
$user->money = $money + 100;