© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
3 replies
Jerome V

How to integrate Laravel Policy in filament v4?

I integrate policy in the v4 like in v3 but glad to see not shown in the menu bar but if no policy it's shown.. is policy still used in v4?

this is my sample policy

<?php

namespace App\Policies;

use App\Models\User;
use App\Enums\User\Role;
use Illuminate\Auth\Access\Response;

class UserPolicy
{
    /**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, User $model): bool
    {
       return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can create models.
     */
    public function create(User $user): bool
    {
       return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can update the model.
     */
    public function update(User $user, User $model): bool
    {
       return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can delete the model.
     */
    public function delete(User $user, User $model): bool
    {
        return false;
    }

    /**
     * Determine whether the user can restore the model.
     */
    public function restore(User $user, User $model): bool
    {
        return false;
    }

    /**
     * Determine whether the user can permanently delete the model.
     */
    public function forceDelete(User $user, User $model): bool
    {
        return false;
    }
}
<?php

namespace App\Policies;

use App\Models\User;
use App\Enums\User\Role;
use Illuminate\Auth\Access\Response;

class UserPolicy
{
    /**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, User $model): bool
    {
       return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can create models.
     */
    public function create(User $user): bool
    {
       return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can update the model.
     */
    public function update(User $user, User $model): bool
    {
       return in_array($user->role, [
                Role::Admin,
                Role::SuperAdmin,
            ]);
    }

    /**
     * Determine whether the user can delete the model.
     */
    public function delete(User $user, User $model): bool
    {
        return false;
    }

    /**
     * Determine whether the user can restore the model.
     */
    public function restore(User $user, User $model): bool
    {
        return false;
    }

    /**
     * Determine whether the user can permanently delete the model.
     */
    public function forceDelete(User $user, User $model): bool
    {
        return false;
    }
}
Solution
Ahh the problem is I forgot to cast the role.. thanks anyways
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

laravel cloud + filament v4 + shield plugin
FilamentFFilament / ❓┊help
3mo ago
How to register CDN in Laravel-Filament?
FilamentFFilament / ❓┊help
17mo ago
How can integrate Socialite in Filament
FilamentFFilament / ❓┊help
14mo ago
How to apply Laravel Policy to Filament Actions (Export/Import/Custom Actions)?
FilamentFFilament / ❓┊help
8mo ago