Package Data | |
---|---|
Maintainer Username: | trexology |
Maintainer Contact: | trexlim@gmail.com (Trex Lim) |
Package Create Date: | 2016-02-03 |
Package Last Update: | 2017-11-10 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-11 15:04:07 |
Package Statistics | |
---|---|
Total Downloads: | 2,953 |
Monthly Downloads: | 3 |
Daily Downloads: | 1 |
Total Stars: | 43 |
Total Watchers: | 6 |
Total Forks: | 29 |
Total Open Issues: | 6 |
Point Transaction system for laravel 5
First, pull in the package through Composer.
composer require trexology/pointable
And then include the service provider within app/config/app.php
.
'providers' => [
Trexology\Pointable\PointableServiceProvider::class
];
At last you need to publish and run the migration.
php artisan vendor:publish --provider="Trexology\Pointable\PointableServiceProvider" && php artisan migrate
<?php
namespace App;
use Trexology\Pointable\Contracts\Pointable;
use Trexology\Pointable\Traits\Pointable as PointableTrait;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements Pointable
{
use PointableTrait;
}
$user = User::first();
$amount = 10; // (Double) Can be a negative value
$message = "The reason for this transaction";
//Optional (if you modify the point_transaction table)
$data = [
'ref_id' => 'someReferId',
];
$transaction = $user->addPoints($amount,$message,$data);
dd($transaction);
$user = User::first();
$points = $user->currentPoints();
dd($points);
$user = User::first();
$user->transactions;
//OR
//$user['transactions'] = $user->transactions(2)->get(); //Get last 2 transactions
dd($user);
$user = User::first();
$user['transactions_total'] = $user->countTransactions();
dd($user);