Laravel-permission: The Documentation is not practical

Created on 21 Aug 2017  路  5Comments  路  Source: spatie/laravel-permission

I've been deli erating whether or not to use this package or just build the functionality from scratch.
The Documentation is not practical enough for me to see how to apply it to my application
I want to create an app with certain roles and permissions already defined , the only thing needed would be to assign it to users.

From the documentation I can't see where to just create roles and permissions without it being dynamic.. instead I'm getting confused with functionalities I probably won't need

All 5 comments


  1. > I want to create an app with certain roles and permissions already defined
    > From the documentation I can't see where to just create roles and permissions without it being dynamic

For hard-coded roles and permissions, you could use the example Database Seed from the readme:

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

class RolesAndPermissionsSeeder extends Seeder
{
    public function run()
    {
        // Reset cached roles and permissions
        app()['cache']->forget('spatie.permission.cache');

        // create permissions
        Permission::create(['name' => 'edit posts']);
        Permission::create(['name' => 'delete posts']);
        Permission::create(['name' => 'delete users']);

        // create roles and assign existing permissions
        $role = Role::create(['name' => 'Author']);
        $role->givePermissionTo('edit posts');
        $role->givePermissionTo('delete posts');

        $role = Role::create(['name' => 'Manager']);
        $role->givePermissionTo('delete users');
    }
}

Or if you don't like using a seeder, you can put the same code into your app anywhere you wish.


  1. > the only thing needed would be to assign it to users.

To assign roles to users, you can:

$user = User::find($id);

// Adding permissions to a user
$user->givePermissionTo('edit posts');

// or

// Adding permissions via a role
$user->assignRole('Author');

And then you can use @can('edit posts') or auth()->user()->can('edit posts') to conditionally test for authorization against those permissions.

3.

instead I'm getting confused with functionalities I probably won't need

Not everyone will use every feature. But, which ones do you think you won't need, and why? Perhaps discussing some specifics may help us give you clarity.


  1. > The Documentation is not practical enough for me to see how to apply it to my application

Got an example of the kind of documentation you consider to be "practical enough"? Perhaps we can use that as inspiration to make improvements to our own.

Thank you for clarifying it out for me

Most of your documentations are not practical the most practical one is the mediaLibrary one

Most of your documentations are not practical

We try to make things as clear as possible. If you see something that can explained better, please let us know. Generally we're very open for PRs that improve the code and docs.

I just read the thread again and I would like to apologise if I sounded rude... I have a personality disorder and it affects me at times

I think your docs are from the point of view of talented coders like yourselves but it doesn't really take into consideration noobs like me and some others

When I read your documentation it's like I'm reading through an api... like a it's just a list of functions and methods and all

I think you can try to see from the point of view of some of us that are on a deadline and don't have time to go through the whole docs... it should show how to get started quick without having to do too much...
Like that data are seed was at the bottom of the docs so I'm already confused halfway reading through a bunch of methods I don't need trying to grasp it

I just read the thread again and I would like to apologise if I sounded rude... I have a personality disorder and it affects me at times

No apologies needed. I welcome any kind of feedback that makes this package better.

Feel free to send PRs to the docs to improve them. Personally I think the current docs are fine for most beginners too. But yeah, like using most packages, you should take the effort to go through the docs at least once.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dreambox13 picture Dreambox13  路  3Comments

MichalKrakow picture MichalKrakow  路  4Comments

dylangeorgeharbour picture dylangeorgeharbour  路  3Comments

bbdangar picture bbdangar  路  4Comments

holymp2006 picture holymp2006  路  4Comments