PHP code example of ivanaquino / laravel-credithub

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

    

ivanaquino / laravel-credithub example snippets


return [
    'type_field' => 'string',
];

// ...
use IvanAquino\LaravelCredithub\Contracts\HasCredits;
use IvanAquino\LaravelCredithub\Traits\CreditTransactional;

class User extends Model implements HasCredits
{
    use CreditTransactional;
}
// ...

$user = User::find(1);
# Add credits
$user->addCredits(100);
$user->addCredits(100, 'Bonus');
$user->addCredits(100, 'Bonus', ['my_custom_field' => 'my_custom_value']);
# Subtract credits
$user->subtractCredits(100);
$user->subtractCredits(100, 'Withdraw');
$user->subtractCredits(100, 'Withdraw', ['my_custom_field' => 'my_custom_value']);
# Transfer credits
$user->transferCreditsTo(100, $anotherUser);
$user->transferCreditsTo(100, $anotherUser, 'Transfer');
$user->transferCreditsTo(100, $anotherUser, 'Transfer', ['my_custom_field' => 'my_custom_value']);

# Get credits
$user->credit_balance; // integer
$user->has_credits; // true or false

return [
    'type_field' => \App\Enums\CreditTransactionType::class,
];

use \App\Enums\CreditTransactionType;

$user = User::find(1);
# Add credits
$user->addCredits(100, CreditTransactionType::BONUS);
bash
php artisan vendor:publish --tag="credithub-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="credithub-config"