1. Go to this page and download the library: Download climactic/laravel-credits 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/ */
climactic / laravel-credits example snippets
return [
// Allow negative balances
'allow_negative_balance' => false,
// Table name for credit transactions (change if you've updated the migration table name)
'table_name' => 'credits',
];
use Climactic\Credits\Traits\HasCredits;
class User extends Model
{
use HasCredits;
}
// Add credits
$user->addCredits(100.00, 'Subscription Activated');
// Deduct credits
$user->deductCredits(50.00, 'Purchase Made');
// Get current balance
$balance = $user->getCurrentBalance();
// Check if user has enough credits
if ($user->hasEnoughCredits(30.00)) {
// Proceed with transaction
}
$sender->transferCredits($recipient, 100.00, 'Paying to user for their service');
// Get last 10 transactions
$history = $user->getTransactionHistory();
// Get last 20 transactions in ascending order
$history = $user->getTransactionHistory(20, 'asc');
$date = new DateTime('2023-01-01');
$balanceAsOf = $user->getBalanceAsOf($date);