Git Product home page Git Product logo

Comments (3)

mabasic avatar mabasic commented on July 3, 2024 1

Wow, this is great stuff. I like the PRs and will merge as soon as we resolve the issues that I commented upon.

from comments.

mabasic avatar mabasic commented on July 3, 2024

You could opt out of package discovery for this package and then write your own service provider by copying the package service provider, changing the gate checks and then registering that service provider in your config/app.php.

I think that that should work.

P.S. This is the first thing that came to my mind. Maybe there is a simpler way of just overriding the gate check.

from comments.

macagoraga avatar macagoraga commented on July 3, 2024

I think a similar solution as well, but maybe using a Policy class and then define in config which one to use, will allow to override without duplicate code of ServiceProvider.

I make a pull request, if you want to check into.

  1. I add new CommentPolicy.php

  2. I updated ServiceProvider.php how is defined the permission, using:

        // Define permission defined in config
        $permissions = config('comments.permissions', [
            'create-comment' => 'Laravelista\Comments\CommentPolicy@create',
            'delete-comment' => 'Laravelista\Comments\CommentPolicy@delete',
            'edit-comment' => 'Laravelista\Comments\CommentPolicy@update',
            'reply-to-comment' => 'Laravelista\Comments\CommentPolicy@reply',
        ]);
        foreach($permissions as $permission => $policy) {
            Gate::define($permission, $policy);
        }
  1. In config I added below which can be override by application:
    'permissions' => [
        'create-comment' => 'Laravelista\Comments\CommentPolicy@create',
        'delete-comment' => 'Laravelista\Comments\CommentPolicy@delete',
        'edit-comment' => 'Laravelista\Comments\CommentPolicy@update',
        'reply-to-comment' => 'Laravelista\Comments\CommentPolicy@reply',
    ]
  1. I also added new permission for create-comment, which per default is true. So in controller store method I add $this->authorize('create-comment', Comment::class);

The rest is untouched so it should not break anything else.

from comments.

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.