- How do I add a preview action to a Filament resource table?
- Use the `PreviewAction::make()` method in your resource’s `table()` method. If your model lacks a `previewUrl` method, define a custom URL resolver via the `using()` closure, like `PreviewAction::make()->using(fn($record) => route('posts.show', $record))`.
- Does this package work with Filament v3+ only?
- Yes, this package requires Filament v3+ (or v4+). If you’re on an older version, upgrade Filament first or check for a compatible fork. The README confirms Laravel 11/10 support, but Filament version compatibility is critical.
- What if my frontend routes use dynamic slugs (e.g., `/posts/{slug}`) instead of IDs?
- Override the `getPreviewUrl()` method in your resource class to return the correct route. For example, `return route('posts.show', ['slug' => $this->slug]);`. The package won’t auto-detect dynamic slugs, so custom logic is required.
- Can I restrict preview access to specific roles or permissions?
- Yes, use Filament’s built-in action modifiers like `visible()` or `requiresConfirmation()`. For role-based access, leverage Filament’s policy system or middleware. Example: `PreviewAction::make()->visible(fn($livewire) => $livewire->getUser()->can('preview-posts'))`.
- Will previews trigger extra database queries or slow down Filament?
- No, previews are purely frontend URL-based and don’t load additional data by default. However, if your frontend route resolves eager-loaded relationships, ensure your model uses `with()` or caching to avoid N+1 queries during previews.
- How do I test preview actions in PHPUnit?
- Mock the `PreviewAction` by stubbing the `getPreviewUrl()` method or using Laravel’s HTTP test helpers. For example, `PreviewAction::shouldReceive('getPreviewUrl')->andReturn(route('posts.show', 1));` in your test setup.
- Does this package support multi-tenancy (e.g., Laravel Nova-like setups)?
- Not out of the box. For multi-tenancy, override `getPreviewUrl()` to include tenant-aware routes or middleware. Example: `return route('tenants.posts.show', ['tenant' => auth()->tenant(), 'post' => $this])`.
- What if my frontend isn’t Laravel-based (e.g., React/Node.js API)?
- This package assumes Laravel frontend routes. For non-Laravel frontends, you’ll need to manually generate preview URLs (e.g., API endpoints) or use a different solution like browser extensions for manual previews.
- How do I customize the preview button label or icon?
- Use Filament’s action modifiers. For example, `PreviewAction::make()->label('Live Preview')->icon('eye')`. You can also publish and translate language files with `php artisan vendor:publish --tag=lang` for full customization.
- Is there a risk of breaking changes if Filament v3 evolves post-release?
- Yes, as this package targets Filament v3+, future Filament updates may introduce breaking changes. Monitor the [GitHub repo](https://github.com/novius/laravel-filament-action-preview) for compatibility notes or consider forking if major Filament updates occur.