Twill 3 custom roles & permissions are not working

Hello, I'm trying to create new roles and add permissions to them. i want to make some modules only accessible by some of the new roles I've created. I followed the twill documentation and I still get Forbidden yellow screen error when i try to access a certain module as the new user role i created. here is my code, Models/Enums/UserRole.php
class UserRole extends Enum
{
const VIEWONLY = 'View Only';
const PUBLISHER = 'Publisher';
const ADMIN = 'Admin';

const VIEWER = 'Viewer';
const EDITOR = 'Editor';
}
class UserRole extends Enum
{
const VIEWONLY = 'View Only';
const PUBLISHER = 'Publisher';
const ADMIN = 'Admin';

const VIEWER = 'Viewer';
const EDITOR = 'Editor';
}
Providers/AppServiceProvider.php
public function register(): void
{ \A17\Twill\Facades\TwillPermissions::setRoleEnum(\App\Models\Enums\UserRole::class);
}
public function register(): void
{ \A17\Twill\Facades\TwillPermissions::setRoleEnum(\App\Models\Enums\UserRole::class);
}
Providers/AuthServiceProvider.php
public function boot(): void
{
Gate::define('list', function ($user) {
return in_array($user->role_value, [
UserRole::VIEWONLY,
UserRole::VIEWER,
UserRole::EDITOR,
UserRole::ADMIN
]);
});
}
public function boot(): void
{
Gate::define('list', function ($user) {
return in_array($user->role_value, [
UserRole::VIEWONLY,
UserRole::VIEWER,
UserRole::EDITOR,
UserRole::ADMIN
]);
});
}
It looks like the code in AuthServiceProvider is not redefining twill's default permissions. how do i fix this?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?