- How do I install and set up Labrodev Contactable in a Laravel 12+ project?
- Run `composer require labrodev/contactable`, then publish the config with `php artisan vendor:publish --tag=contactable-config`. Edit `config/contactable.php` to define fields, model persistence, and notification channels. Ensure Livewire 4+ is installed and included in your Blade layouts.
- Can I use Contactable without saving submissions to a database?
- Yes. Set the `model` key in `config/contactable.php` to `null` to disable Eloquent persistence. The form will still work for notifications (mail, log, or webhook) without requiring a database table.
- What validation rules are supported, and how do I customize them?
- Contactable supports standard Laravel validation rules (e.g., `required`, `email`, `min:5`). Define them in the `rules` key of each field in `config/contactable.php`. Custom messages can be added via the `messages` key or translated using Laravel’s `__()` helper.
- How do I handle notifications (mail, webhook, log) if one fails?
- Contactable processes notifications sequentially. If mail fails, the webhook or log will still execute unless you implement custom error handling. For resilience, consider queueing notifications (e.g., `Mail::to()->later()`) or adding fallback logic in your notification channel.
- Is Contactable compatible with Laravel 11 or older versions?
- No. Contactable requires **Laravel 12+** and **PHP 8.2+** due to Livewire 4+ dependencies. If you’re on Laravel 11 or older, you’ll need to upgrade or explore alternatives like `spatie/laravel-contact` for Blade-based forms.
- Can I customize the form’s success message or redirect behavior dynamically?
- Yes. Use translation keys (e.g., `contactable::success`) or literal strings in `config/contactable.php` for the success message. For dynamic redirects, set `redirect_route` to a named route or use a closure in a custom Livewire component extending `Contactable`.
- How do I add a file upload field to the contact form?
- Define a field with `type: 'file'` in `config/contactable.php` and add `rules: ['file']` (or custom rules). Publish the views and modify `resources/views/vendor/contactable/livewire/contactable.blade.php` to include a file input. Handle storage manually in a custom Livewire component if needed.
- What if I need rate limiting or CSRF protection beyond Laravel’s defaults?
- Contactable relies on Laravel’s built-in protections (CSRF middleware, rate limiting). Add `@method('POST')` to your Livewire component or wrap the form in a route middleware (e.g., `throttle:60,1`). For Livewire-specific rate limiting, use `use ThrottlesRequests;` in a custom component.
- Are there alternatives to Contactable for non-Livewire Laravel projects?
- For Blade-only projects, consider `spatie/laravel-contact` or `laravelcollective/html`. If using Inertia.js/Vue/React, build a custom API endpoint with Laravel’s Form Request validation and handle frontend submission logic separately. Contactable is Livewire-specific.
- How do I test Contactable’s form submission and notifications in CI?
- Mock notifications in tests by overriding the `notify()` method in a custom Livewire component or using Laravel’s `fake()` helpers. Test validation with `Livewire::test()` and assert flash messages or redirects. For webhooks, use `Http::fake()` to verify requests.