Coder Social home page Coder Social logo

Add method in Role model about bouncer HOT 3 CLOSED

josephsilber avatar josephsilber commented on May 21, 2024
Add method in Role model

from bouncer.

Comments (3)

JosephSilber avatar JosephSilber commented on May 21, 2024

You can add your own methods to the role model by extending it:

namespace App;

use Silber\Bouncer\Database\Role as BaseRole;

class Role extends BaseRole
{
    public function scopeOrderedList($query)
    {
        return $query->orderBy('name')->lists('name', 'id');
    }
}

Once you've created your own extended model, simply tell Bouncer to use it:

Bouncer::useRoleModel(\App\Role::class);

Stick that into your AppServiceProvider's boot method, and you're good to go!

from bouncer.

swimlappy avatar swimlappy commented on May 21, 2024

Excellent! That keeps things clean. Thanks! And I really like Bouncer, perfect for an app I'm working on!

from bouncer.

dhcmega avatar dhcmega commented on May 21, 2024

Hi, is this still the way to go? Because with last versions (Laravel 5.5.14, Bouncer v1.0.0-beta.4) if I change the RoleModel with Bouncer::useRoleModel(\App\Role::class), I get "This action is unauthorized".

Thanks!
dhcmega

Edit: The problem was that the permission table had "roles" for entity_type, and now it should be "App\Modes\Role", which is my namespace. Odd that it wasn't originally "Silber\Bouncer\Database\Role"

from bouncer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.