© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
4 replies
Sharpshooter

Delete method inside model policy not working after editing

I tried to disable/hide the delete function when a customer has any comments. It works normally. However, after updating the customer, the delete button appears, which shouldn't be there.

Example Code:
// app\Policies\Shop\CustomerPolicy.php
class CustomerPolicy
{

    public function delete(User $user, Customer $customer): bool
    {
        if ($customer->comments_exists) {
            return false;
        }

        return true;
    }

}

// app\Filament\Resources\Shop\Customers\CustomerResource.php
class CustomerResource extends Resource
{

    // ...
    
    /** @return Builder<Customer> */
    public static function getEloquentQuery(): Builder
    {
        return parent::getEloquentQuery()->with('addresses')->withoutGlobalScope(SoftDeletingScope::class)->withExists('comments');
    }
}
// app\Policies\Shop\CustomerPolicy.php
class CustomerPolicy
{

    public function delete(User $user, Customer $customer): bool
    {
        if ($customer->comments_exists) {
            return false;
        }

        return true;
    }

}

// app\Filament\Resources\Shop\Customers\CustomerResource.php
class CustomerResource extends Resource
{

    // ...
    
    /** @return Builder<Customer> */
    public static function getEloquentQuery(): Builder
    {
        return parent::getEloquentQuery()->with('addresses')->withoutGlobalScope(SoftDeletingScope::class)->withExists('comments');
    }
}
Solution
I found a workaround for this, inside the delete method policy I added this code:
public function delete(User $user, Customer $customer): bool
{
    if ($customer->comments_exists ?? $customer->comments()->exists()) {
        return false;
    }

    return true;
}
public function delete(User $user, Customer $customer): bool
{
    if ($customer->comments_exists ?? $customer->comments()->exists()) {
        return false;
    }

    return true;
}


Does anyone know why this is happening?
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

Model Policy on page not working
FilamentFFilament / ❓┊help
2y ago
getUrl() Method not working on Model
FilamentFFilament / ❓┊help
2y ago
Translations plugin model not accepting Policy
FilamentFFilament / ❓┊help
3y ago
after() method of DetachAction is not working
FilamentFFilament / ❓┊help
3y ago