- How do I install and set up Laravel Notify in a Laravel 11 project?
- Run `composer require mckenziearts/laravel-notify`, then publish the config and assets with `php artisan vendor:publish --tag=notify-assets --tag=notify-config`. Add `<x-notify::notify />` to your Blade layout and ensure Alpine.js is loaded. For Tailwind CSS, update your `app.css` to include the package’s Blade files via `@source`.
- Can I use Laravel Notify without Tailwind CSS or Alpine.js?
- Yes, but with limitations. The package provides pre-compiled assets for non-Tailwind projects, though customization may require manual CSS overrides. Alpine.js is required for interactivity (auto-dismiss, animations), but you can disable these features if needed. For vanilla JS fallbacks, you’ll need to extend the Blade component.
- What Laravel versions does this package support, and what’s the PHP requirement?
- Laravel Notify is officially tested with Laravel 10–13 and requires PHP 8.1+. Older Laravel versions (e.g., 9.x) may work but aren’t guaranteed due to dependency changes. Always check the [GitHub actions](https://github.com/mckenziearts/laravel-notify/actions) for compatibility updates.
- How do I trigger a notification from a controller or middleware?
- Use the `notify()` facade: `notify()->success()->title('Action completed')->send()`. For middleware, inject the facade or use `session()->flash()` with the package’s session keys. Notifications are session-based, so they’ll appear on the next request (e.g., after a redirect).
- Are notifications accessible (WCAG compliant) by default?
- The package includes ARIA attributes and keyboard navigation support out of the box, but full WCAG compliance depends on your customization. For critical accessibility needs, review the Blade component (`resources/views/vendor/notify/notify.blade.php`) and override it to add features like screen reader announcements or contrast adjustments.
- What happens if a user has JavaScript disabled? Will notifications still work?
- Notifications rely on Alpine.js for dynamic behavior (e.g., auto-dismiss, animations), but the core functionality—displaying flash messages—works without JS. The package renders notifications as static HTML if JS fails. For critical feedback, pair with Laravel’s native `session()->flash()` as a fallback.
- Can I customize the notification styles beyond Tailwind’s defaults?
- Yes, publish the assets (`php artisan vendor:publish --tag=notify-assets`) to override the Blade component and CSS. For Tailwind projects, extend your `tailwind.config.js` to customize colors, spacing, or animations. Non-Tailwind users must manually override the pre-compiled styles in their CSS.
- Does Laravel Notify work with Laravel Livewire or Inertia.js?
- The package is Blade-focused and works alongside Livewire/Inertia, but integration requires careful handling. For Livewire, trigger notifications in component methods and ensure Alpine.js doesn’t conflict with Livewire’s reactivity. Inertia.js projects may need to adapt the Blade component to React/Vue syntax, as notifications rely on server-rendered flash data.
- How do I test notifications in PHPUnit? Are there built-in helpers?
- There are no built-in test helpers, but you can test notifications by flashing session data manually in tests: `session()->flash('notify', ['type' => 'success', 'title' => 'Test']);` and asserting the Blade component renders correctly. Mock the `notify()` facade or use HTTP tests to simulate redirects with notifications.
- What are the alternatives to Laravel Notify for flash notifications?
- Alternatives include `spatie/laravel-flash` (simpler, no frontend dependencies), `darkaonline/l5-swagger` (for API docs), or `torann/laravel-notification-channels` (for multi-channel notifications). For Tailwind/Alpine.js integration, `filament/support` (Filament’s notification system) is another option, though it’s heavier. Choose based on your need for frontend interactivity.