Package Data | |
---|---|
Maintainer Username: | henriale |
Maintainer Contact: | alexandreh.araujo@gmail.com (Alexandre Araujo) |
Package Create Date: | 2016-03-24 |
Package Last Update: | 2016-04-12 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:08:55 |
Package Statistics | |
---|---|
Total Downloads: | 132 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A plan/resource auditor for Laravel.
1 - Firstly, place the package into your project using composer:
$ composer require henriale/stinter
$ composer composer update
2 - Then, create a /config/stinters.php
file or just publish it with the following command:
$ php artisan vendor:publish --provider="Henriale\Stinter\StintServiceProvider"
1 - Create a restriction/stint class to control your resources:
$ php artisan make:stint CreateProduct
2 - Make some validation with it
class CreateProduct extends Stinter
{
protected $basicPlanLimitation = 10;
public function check(Authenticatable $user)
{
if ($user->products()->count() >= $this->basicPlanLimitation) {
// user has too many products
return false;
}
//user still can have more products
return true;
}
}
3 - Now, register in /config/stinters.php
so the auditor can check it when triggered
return [
\App\Stinters\CreateProduct::class
];
4 - Finally, use \Gate
class passing the stint FQN to handle its permission:
<!-- using User model -->
<?php
if ($user->can(\App\Stinters\CreateProduct::class)) {
echo 'yes, he is able';
}
?>
<!-- using Gate -->
<?php
$userCan = \Gate::allows(\App\Stinters\CreateProduct::class);
if ($userCan) {
echo "user can create more stuffs";
} else {
echo "user cannot create more stuffs. he better upgrade his plan/subscription!";
}
?>
<!-- using blade -->
@can(\App\Stinters\CreateProduct::class)
// can
@else
// cannot
@endcan