maximkou/laravel-simple-voters
Larablocks Analysis
maximkou/laravel-simple-voters works with Laravel 5 (latest release 0.2, May 16, 2017), which reached end of life: no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5, past end of life
- No release in the last 12 months (last: May 16, 2017)
- 0 downloads a month (needs 10,000)
- 3 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: May 16, 2017.
- No releases in the last 12 months.
- First released: May 12, 2017.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.
| Install | |
|---|---|
composer require maximkou/laravel-simple-voters |
|
| Latest Version: | 0.2 |
| PHP: | >=7.0 |
| Laravel: | 5 |
| License: | MIT |
| Last Updated: | May 16, 2017 |
| Links: | GitHub · Packagist |
Laravel 5 Voters System
This package provide Symfony Security Voters like system, which allow you to check object-based access.
Using examples
Check, is current user can edit specific Post:
is_granted('edit', $post) // return true or false
// or using Facade
Access::isGranted('edit', $post)
Check, is specific user can read or write specific Post info:
is_granted(['read', 'write'], $post, $user) // return true or false
// or using Facade
Access::isGranted(['read', 'write'], $post, $user)
Installation:
Require dependency using composer:
composer require maximkou/laravel-simple-voters ^0.1
Add service provider to your config/app.php:
'providers' => [
Maximkou\SimpleVoters\SimpleVotersServiceProvider::class,
Add facade alias to your config/app.php (optional):
'aliases' => [
'Access' => Maximkou\SimpleVoters\Facades\Access::class,
Publish package config (optional):
php artisan vendor:publish --provider="Maximkou\SimpleVoters\SimpleVotersServiceProvider"
Configuration:
// file config/voters.php
/**
* Available out of the box strategies: affirmative, unanimous, consensus.
* You can use custom voting strategy by registering service with name 'simple_voters.strategies.{strategy_name}'
*/
'strategy' => 'unanimous',
/**
* If pro and contra votes count is equal, or all voters abstain, used this value
*/
'is_granted_by_default' => true,
/**
* List of Voter classes.
*/
'voters' => [
// put here your voters classes
],
Creating Voter
Voter must implement Maximkou\SimpleVoters\Contracts\Voter or extend Maximkou\SimpleVoters\AbstractVoter class.
Then add your voter to config.
Example:
class PostVoter extends AbstractVoter
{
protected function supports($action, $object)
{
return in_array('action', ['edit', 'remove']) && $object instanceOf Post;
}
protected function isGranted($action, $object, $user)
{
$checker = "can".ucfirst($action);
return $this->$checker($object, $user);
}
private function canEdit($object, $user)
{
return $object->user_id = $user->id;
}
private function canRemove($object, $user)
{
return $object->user_id = $user->id;
}
}
Using in non-laravel context
For using in non-laravel context, you only must create custom AuthenticatedUserResolver, for resolving current user instance.
Example:
use Maximkou\SimpleVoters\Services\Access;
use Maximkou\SimpleVoters\GrantStrategies;
$accessChecker = new Access(
new GrantStrategies\Affirmative($listVoters), // choose voting strategy
new MyAuthUserResolver() // pass your user resolver
);
$accessChecker->isGranted('action', $object); // true/false?
License
This package is open-sourced software licensed under the MIT license.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 0.2 | >=7.0 | 5.0.x| | MIT | |
| 0.1 | >=7.0 | 5.0.x| | MIT |