Skip to main content
Back to packages
181 GitHub stars

nabilhassen/laravel-usage-limiter

View on GitHub

Description

Track, limit, & restrict usages of users, accounts, or any other model.

Basic Usage

First, you need to use the HasLimits trait on your model.

use NabilHassen\LaravelUsageLimiter\Traits\HasLimits;
 
class User extends Authenticatable
{
use HasLimits;
}

Create your Limits

# On standard plan 5 projects are allowed per month
$projectsStandardLimit = Limit::create([
'name' => 'projects',
'allowed_amount' => 5,
'plan' => 'standard', // optional
'reset_frequency' => 'every month' // optional
]);
 
# On pro plan 10 projects are allowed per month
$projectsProLimit = Limit::create([
'name' => 'projects',
'allowed_amount' => 10,
'plan' => 'pro', // optional
'reset_frequency' => 'every month' // optional
]);
 
# Increment projects limit on standard plan from 5 to 15 per month
$projectsStandardLimit->incrementBy(10);
 
# Decrement projects limit on pro plan from 10 to 7 per month
$projectsProLimit->decrementBy(3);

Related Content on Laravel Daily

Video

Recent Courses on Laravel Daily

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.