Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

User Permission Bundle Laravel Package

effinix/user-permission-bundle

View on GitHub
Deep Wiki
Context7

Easily protect routes with unique permissions

With one easy attribute, you can now protect controller methods and invokable controllers e.g:

src/Controller/Controller.php
<?php declare(strict_types=1);

namespace App\Controller;

use Effinix\UserPermissionBundle\Attribute\Attribute\Routing\RequirePermission;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;

#[AsController]
class Controller
{
    #[Route(
        name: 'public_website',
    )]
    #[RequirePermission('login')]
    public function index()
    {
        return new Response("Hello world!");
    }
}

Implement UserInterface to provide access to these routes

src/Entity/User.php
<?php declare(strict_types=1);

namespace App\Entity;

use Effinix\UserPermissionBundle\DependencyInversion\UserInterface;

class User implements UserInterface
{
    ...
    public function hasPermission(string $permission) : bool {
        // check if the permission is valid for this user
        return in_array($permission, $this->getPermissions());
    }
    
    /**
     * @return string[]
     */
    public function getPermissions() : array {
        // domain logic way of getting user permissions (e.g. storing in the database)
        return ['login'];
    }
}

Default config file:

effinix_user_permission:
  permission_store:
    provider:
    permissions:
      - login
  do_cache: true

when@dev:
  effinix_user_permission:
    do_cache: false
    logger: app.my-logger
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver