This package counts the amount of records on a relationship and compares them with a given set of limits. This can be useful to determine if a user has reached the limit of files he can upload or something similar.
Require this package, with Composer, in the root directory of your project.
$ composer require artisanry/doorkeeper
<?php
namespace App;
use Artisanry\Doorkeeper\Traits\Doorkeeper;
use Artisanry\Doorkeeper\Contracts\DoorkeeperContract;
class User extends Model implements DoorkeeperContract
{
use Doorkeeper;
public $limits = [
'posts' => 5,
'files' => 10,
];
public function posts() {
return $this->hasMany('App\Post');
}
public function files() {
return $this->hasMany('App\File');
}
}
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class ReachedLimits
{
public function handle($request, Closure $next)
{
$user = Auth::check();
if ( $user->limits($user->subscription->limits)->fails() ) {
return redirect()->route('billing');
}
return $next($request);
}
}
<?php
namespace App\Http\Controllers;
class DashboardController
{
public function __construct()
{
$this->middleware('reachedLimits');
}
public function index()
{
return view('dashboard');
}
}
$user->limits($user->subscription->limits)->passes();
$user->limits($user->subscription->limits)->fails();
$user->passes();
$user->fails();
$user->allowed();
$user->allowed('posts');
$user->current();
$user->current('posts');
$user->maxed();
$user->maxed('posts');
$ phpunit
If you discover a security vulnerability within this package, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.
This project exists thanks to all the people who contribute.
Mozilla Public License Version 2.0 (MPL-2.0).