Giter Club home page Giter Club logo

promocodes's Introduction

Promocodes

PR0M0C0D35

Latest Stable Version Total Downloads License

Promotional Codes Generator for Laravel 5.*

Table of Contents

Installation

Composer

Run composer command in your terminal.

composer require trexology/promocodes

Laravel

Please read Config 'n Migration section first. It's requried to create promocodes table

Open config/app.php and find the providers key. Add PromocodesServiceProvider to the array.

Trexology\Promocodes\PromocodesServiceProvider::class

Find the aliases key and add Facade to the array.

'Promocodes' => Trexology\Promocodes\Facades\Promocodes::class

Usage

Recomendations

Run php artisan make:model Promocode and update app/Promocode.php as following:

/**
 * @var bool
 */
public $timestamps = false;

/**
 * @var array
 */
protected $fillable = [
	'code',
	'reward',
	'quantity',
  'is_used',
];

Methods

You can generate Promotional codes using generate method.

The only parameter is amount of codes to generate.

Promocodes::generate(5); // $amount = 1
  • $amount int - number of promotional codes to be generated

This method will return array of codes with 5 element


You can generate and save codes instantly in your database using:

Promocodes::generateAndSave(5, 10.50); // $amount = 1, $reward = null
  • $amount int - number of promotional codes to be generated
  • $reward double - amount of reward of each promocodes

This will generate 5 codes and insert in your DB.


You can generate and save codes with the exact name in your database using:

Example:

Promocodes::generateCodeName("OFF20%", 0.2); // $reward = null (percentage discount)
Promocodes::generateCodeName("5SGDOFF", 5); // $reward = null (dollar discount)
  • $code string - exact promotional code name to be generated
  • $reward double - amount of reward of each promocodes

This will return false if code name already existed


Check code using method check.

Method returns boolean.

$valid = Promocodes::check('TEST-CODE'); // $promocode
  • $promocode string - promotional code wich will be checked if issets

Laslty use code using method apply.

Method returns boolean.

$applied = Promocodes::apply('TEST-CODE', true); // $promocode, $hard_check = false
  • $promocode string - promotional code wich will be checked if issets, and applied to current user
  • $hard_check boolean - if false or null, you will get only boolean value of checked promocode. If true you will get amount of reward as double or false.

If method returns false, code was already used or it wasn't valid

Config 'n Migration

Publish Promocodes config & migration file using command:

php artisan vendor:publish

Created file config\promocodes.php. Inside you can change configuration as you wish. Created migration file, now you can simply run php artisan migrate and that's it, you will have promocodes table.

License

Promocodes is an open-sourced laravel package licensed under the MIT license

TODO

  • Create migration for vendor publish

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.