FilamentF
Filament3y ago
Finn

Enable relational manager table actions based on a policy

I have a policy for my notes table (which is only accessible through a different resource's relational manager) where I want to allow a record to be updated or deleted only by users that have authorization via said policy. Does anyone know how I can go about doing this?

NotePolicy.php
<?php

namespace App\Policies;

use App\Models\Note;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class NotePolicy
{
    use HandlesAuthorization;

    public function update(User $user, Note $note): bool
    {
        return $user->id === $note->user_id;
    }

    public function delete(User $user, Note $note): bool
    {
        return $user->id === $note->user_id;
    }

}


NotesRelationalManager.php (current, non-working attempt)
...

  ->actions([
    Tables\Actions\ViewAction::make(),
    Tables\Actions\EditAction::make()
      ->visible(auth()->user()->can('update', $this)),
    Tables\Actions\DeleteAction::make()
      ->visible(auth()->user()->can('update', $this)),
  ])
...
Was this page helpful?