Giter Site home page Giter Site logo

laravel-pointable's Introduction

Latest Stable Version Total Downloads Latest Unstable Version License

Laravel Pointable

Point Transaction system for Laravel 5

Original Package from Trexology

Installation

First, pull in the package through Composer.

composer require alariva/laravel-pointable

And then include the service provider within app/config/app.php.

'providers' => [
    Alariva\Pointable\PointableServiceProvider::class
];

At last you need to publish and run the migration.

php artisan vendor:publish --provider="Alariva\Pointable\PointableServiceProvider" && php artisan migrate

Setup a Model

<?php

namespace App;

use Alariva\Pointable\Contracts\Pointable;
use Alariva\Pointable\Traits\Pointable as PointableTrait;
use Illuminate\Database\Eloquent\Model;

class User extends Model implements Pointable
{
    use PointableTrait;
}

Add Points

$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);

Get Current Points

$user = User::first();
$points = $user->currentPoints();

dd($points);

Get Transactions

$user = User::first();
$user->transactions;

//OR
//$user['transactions'] = $user->transactions(2)->get(); //Get last 2 transactions

dd($user);

Count Transactions

$user = User::first();
$user['transactions_total'] = $user->countTransactions();

dd($user);

laravel-pointable's People

Contributors

alariva avatar trexology avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.