Package Data | |
---|---|
Maintainer Username: | trexology |
Package Create Date: | 2016-08-08 |
Package Last Update: | 2024-03-13 |
Home Page: | http://zgabievi.github.io/Promocodes |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-16 15:03:09 |
Package Statistics | |
---|---|
Total Downloads: | 1,069 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 12 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 2 |
Promotional Codes Generator for Laravel 5.*
Run composer command in your terminal.
composer require trexology/promocodes
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
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',
];
You can generate Promotional codes using generate
method.
The only parameter is amount of codes to generate.
Promocodes::generate(5); // $amount = 1
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
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)
This will return false if code name already existed
Check code using method check
.
Method returns boolean.
$valid = Promocodes::check('TEST-CODE'); // $promocode
Laslty use code using method apply
.
Method returns boolean.
$applied = Promocodes::apply('TEST-CODE', true); // $promocode, $hard_check = false
If method returns false, code was already used or it wasn't valid
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.
Promocodes is an open-sourced laravel package licensed under the MIT license