Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup RolePolicy? #42

Closed
horaceho opened this issue Oct 5, 2018 · 1 comment
Closed

How to setup RolePolicy? #42

horaceho opened this issue Oct 5, 2018 · 1 comment

Comments

@horaceho
Copy link

horaceho commented Oct 5, 2018

Originally posted by @vyuldashev in #27 (comment)

After php artisan make:policy RolePolicy --model=Role:

<?php

namespace App\Policies;

use App\User;
use Vyuldashev\NovaPermission\Role;
use Illuminate\Auth\Access\HandlesAuthorization;

class RolePolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any company.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function viewAny(User $user)
    {
        return false;
    }

    /**
     * Determine whether the user can view the role.
     *
     * @param  \App\User  $user
     * @param  \App\Role  $role
     * @return mixed
     */
    public function view(User $user, Role $role)
    {
        //
    }

    ...

and update AuthServiceProvider:

<?php

namespace App\Providers;

use App\Company;
use Vyuldashev\NovaPermission\Role;
use Vyuldashev\NovaPermission\Permission;

use App\Policies\CompanyPolicy;
use App\Policies\RolePolicy;
use App\Policies\PermissionPolicy;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
        Company::class => CompanyPolicy::class,
        Role::class => RolePolicy::class,
        Permission::class => PermissionPolicy::class,
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        //
    }
}

There is no effect. View, edit and delete icons are still there:

roles

Did I get the vyuldashev Role model namespace wrong?

@horaceho
Copy link
Author

horaceho commented Oct 5, 2018

Oops, should be:

use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant