swisnl / json-api-server

Set up a JSON API in Laravel in just a few minutes.
MIT License
105 stars 19 forks source link

Permissions, missing instructions #5

Closed liepumartins closed 6 years ago

liepumartins commented 6 years ago

When running tests I encounter: BadMethodCallException : Call to undefined method App\User::givePermissionTo()

Reading through the README I did not see any information about required package or other instructions how to enable permissions for users.

Is it assumed to use spatie/laravel-permission package?

Arnaudvz commented 6 years ago

Hi Liepumartins,

This is indeed a function that requires the spatie/laravel-permission. I think you can fix this problem bij adding the trait Spatie\Permission\Traits\HasRoles to your User model. Hope this helps. I'll check the documentation if this is a missing part.

liepumartins commented 6 years ago

Hi,

Thanks for quick reply!

Next question, still applies to this topic - do I have to seed all permissions manually, generator does not provide this? If I run test I get: Spatie\Permission\Exceptions\PermissionDoesNotExist : There is no permission named retrieve_sample. This happens for each const defined in app/Permissions/SamplePermissions.php and goes away only when I manually insert in permissions table.

I believe generator should use something like this: https://github.com/spatie/laravel-permission#database-seeding

Arnaudvz commented 6 years ago

This is correct what you mention, we have not made a seeder for adding permissions that have been generated. Now that you mention it, this might be an excellent addition to this package.

https://github.com/spatie/laravel-permission#database-seeding Here is an example how to generate a seeder for your problem instead of adding them manually in the table. I will add this to our backlog.