diff --git a/demo/laravel/app/Http/Controllers/DemoController.php b/demo/laravel/app/Http/Controllers/DemoController.php new file mode 100644 index 00000000..0548fe94 --- /dev/null +++ b/demo/laravel/app/Http/Controllers/DemoController.php @@ -0,0 +1,192 @@ +input('type', 'success'); + $message = $request->input('message', 'Notification message'); + $title = $request->input('title'); + $theme = $request->input('theme', 'flasher'); + $adapter = $request->input('adapter', 'flasher'); + $position = $request->input('position', 'top-right'); + $timeout = (int) $request->input('timeout', 5000); + + $flasher = match ($adapter) { + 'toastr' => toastr(), + 'sweetalert' => sweetalert(), + 'noty' => noty(), + 'notyf' => notyf(), + default => flash()->use("theme.{$theme}"), + }; + + $options = [ + 'position' => $position, + 'timeout' => $timeout, + ]; + + if ($adapter === 'toastr') { + $options['positionClass'] = 'toast-' . str_replace('-', '-', $position); + $options['timeOut'] = $timeout; + } elseif ($adapter === 'noty') { + $options['layout'] = match ($position) { + 'top-right' => 'topRight', + 'top-left' => 'topLeft', + 'top-center' => 'topCenter', + 'bottom-right' => 'bottomRight', + 'bottom-left' => 'bottomLeft', + 'bottom-center' => 'bottomCenter', + default => 'topRight', + }; + $options['timeout'] = $timeout; + } elseif ($adapter === 'notyf') { + $positionParts = explode('-', $position); + $options['position'] = [ + 'y' => $positionParts[0] ?? 'top', + 'x' => $positionParts[1] ?? 'right', + ]; + $options['duration'] = $timeout; + } + + if ($title) { + $flasher->{$type}($message, $title, $options); + } else { + $flasher->{$type}($message, $options); + } + + return response()->json(['success' => true]); + } + + public function runExample(Request $request, string $scenario): JsonResponse + { + match ($scenario) { + 'registration' => $this->registrationExample(), + 'login_failed' => $this->loginFailedExample(), + 'validation' => $this->validationExample(), + 'shopping_cart' => $this->shoppingCartExample(), + 'file_upload' => $this->fileUploadExample(), + 'settings' => $this->settingsExample(), + 'payment_success' => $this->paymentSuccessExample(), + 'payment_failed' => $this->paymentFailedExample(), + 'delete_confirm' => $this->deleteConfirmExample(), + 'session_expiring' => $this->sessionExpiringExample(), + default => flash()->info('Example not found'), + }; + + return response()->json(['success' => true]); + } + + private function registrationExample(): void + { + flash()->success('Welcome! Your account has been created.'); + flash()->info('Please check your email to verify your account.'); + } + + private function loginFailedExample(): void + { + flash()->error('Invalid email or password.'); + flash()->info('Forgot your password? Click here to reset.'); + } + + private function validationExample(): void + { + flash()->error('The email field is required.'); + flash()->error('Password must be at least 8 characters.'); + flash()->error('Please accept the terms and conditions.'); + } + + private function shoppingCartExample(): void + { + flash()->success('iPhone 15 Pro added to cart!'); + flash()->warning('Only 2 items left in stock!'); + flash()->info('Add $20 more for free shipping!'); + } + + private function fileUploadExample(): void + { + flash()->success('document.pdf uploaded successfully!'); + flash()->info('File size: 2.4 MB'); + } + + private function settingsExample(): void + { + flash()->success('Settings saved successfully!'); + flash()->info('Some changes may require a page refresh.'); + } + + private function paymentSuccessExample(): void + { + flash()->success('Payment of $149.99 confirmed!'); + flash()->info('Order #12345 - Receipt sent to your email.'); + } + + private function paymentFailedExample(): void + { + flash()->error('Payment declined by your bank.'); + flash()->warning('Please try a different payment method.'); + flash()->info('Your cart has been saved.'); + } + + private function deleteConfirmExample(): void + { + sweetalert() + ->showCancelButton() + ->confirmButtonText('Yes, delete it!') + ->cancelButtonText('Cancel') + ->warning('Are you sure? This cannot be undone.'); + } + + private function sessionExpiringExample(): void + { + flash()->warning('Your session will expire in 5 minutes.'); + flash()->info('Click anywhere to stay logged in.'); + } +} diff --git a/demo/laravel/app/Livewire/ContactForm.php b/demo/laravel/app/Livewire/ContactForm.php new file mode 100644 index 00000000..201780c1 --- /dev/null +++ b/demo/laravel/app/Livewire/ContactForm.php @@ -0,0 +1,36 @@ + 'required|min:2', + 'email' => 'required|email', + 'message' => 'required|min:10', + ]; + + public function submit(): void + { + $this->validate(); + + // Simulate form processing + flash()->success('Message sent successfully!'); + flash()->info('We will respond within 24 hours.'); + + $this->reset(['name', 'email', 'message']); + } + + public function render() + { + return view('livewire.contact-form'); + } +} diff --git a/demo/laravel/app/Livewire/Counter.php b/demo/laravel/app/Livewire/Counter.php index 5ba34d52..72eb9696 100644 --- a/demo/laravel/app/Livewire/Counter.php +++ b/demo/laravel/app/Livewire/Counter.php @@ -1,25 +1,31 @@ success('increment'); - $this->count++; + flash()->success("Count increased to {$this->count}!"); } - public function decrement() + public function decrement(): void { - flash()->info('decrement'); - $this->count--; + flash()->warning("Count decreased to {$this->count}"); + } + + public function reset(): void + { + $this->count = 0; + flash()->info('Counter has been reset.'); } public function render() diff --git a/demo/laravel/app/Livewire/DeleteItem.php b/demo/laravel/app/Livewire/DeleteItem.php new file mode 100644 index 00000000..76cc35f4 --- /dev/null +++ b/demo/laravel/app/Livewire/DeleteItem.php @@ -0,0 +1,41 @@ + 'onConfirmed', + 'sweetalert:denied' => 'onDenied', + ]; + + public function confirmDelete(): void + { + sweetalert() + ->showDenyButton() + ->showCancelButton() + ->confirmButtonText('Yes, delete it!') + ->denyButtonText('Keep it') + ->warning('Are you sure you want to delete this item?'); + } + + public function onConfirmed(array $payload): void + { + // Simulate deletion + flash()->success('Item has been deleted successfully!'); + } + + public function onDenied(array $payload): void + { + flash()->info('The item was kept safe.'); + } + + public function render() + { + return view('livewire.delete-item'); + } +} diff --git a/demo/laravel/resources/views/adapters.blade.php b/demo/laravel/resources/views/adapters.blade.php new file mode 100644 index 00000000..fd402b72 --- /dev/null +++ b/demo/laravel/resources/views/adapters.blade.php @@ -0,0 +1,354 @@ +@extends('layouts.app') + +@section('title', 'Adapters') + +@section('content') +
PHPFlasher supports multiple notification libraries. Choose your favorite!
+Default adapter with 17+ themes
+The default PHPFlasher adapter with beautiful built-in themes. No additional JavaScript libraries required.
+ +composer require php-flasher/flasher-laravel
+ flash()->success('Operation completed!');
+ Simple, elegant toast notifications
+Classic toast notifications with smooth animations. One of the most popular notification libraries.
+ +composer require php-flasher/flasher-toastr-laravel
+ toastr()->success('Data saved successfully!');
+
+// With options
+toastr()
+ ->closeButton()
+ ->progressBar()
+ ->positionClass('toast-top-right')
+ ->success('Profile updated!');
+ Beautiful, responsive, customizable alerts
+Feature-rich modal dialogs with confirmations, inputs, and beautiful animations. Perfect for important user interactions.
+ +composer require php-flasher/flasher-sweetalert-laravel
+ sweetalert()->success('Great job!', 'Success');
+
+// Confirmation dialog
+sweetalert()
+ ->showDenyButton()
+ ->showCancelButton()
+ ->confirmButtonText('Save')
+ ->denyButtonText("Don't save")
+ ->warning('Do you want to save the changes?');
+ Dependency-free notification library
+A flexible, dependency-free notification library with multiple layouts and themes.
+ +composer require php-flasher/flasher-noty-laravel
+ noty()->success('Data saved!');
+
+// With layout options
+noty()
+ ->layout('topCenter')
+ ->timeout(3000)
+ ->progressBar()
+ ->info('Processing your request...');
+ Minimalist, responsive notifications
+A minimalist JavaScript library for toast notifications. Tiny footprint with smooth animations.
+ +composer require php-flasher/flasher-notyf-laravel
+ notyf()->success('Minimal and clean!');
+
+// With options
+notyf()
+ ->position('x', 'right')
+ ->position('y', 'top')
+ ->dismissible(true)
+ ->ripple(true)
+ ->success('File uploaded successfully!');
+ | Feature | +Flasher | +Toastr | +SweetAlert | +Noty | +Notyf | +
|---|---|---|---|---|---|
| Toast Notifications | +Yes | +Yes | +Yes | +Yes | +Yes | +
| Modal Dialogs | +No | +No | +Yes | +No | +No | +
| Confirmations | +No | +No | +Yes | +Yes | +No | +
| Progress Bar | +Yes | +Yes | +Yes | +Yes | +No | +
| Built-in Themes | +17+ | +4 | +1 | +5 | +1 | +
| Dependencies | +None | +jQuery | +None | +None | +None | +
See how PHPFlasher handles common application scenarios. Click to run each example.
+Account creation flow
+Simulates a successful user registration with welcome message and email verification notice.
+ + + +flash()->success('Welcome! Your account has been created.');
+flash()->info('Please check your email to verify your account.');
+ Authentication error
+Shows how to display login failure messages with helpful guidance.
+ + + +flash()->error('Invalid email or password.');
+flash()->info('Forgot your password? Click here to reset.');
+ Multiple field errors
+Demonstrates displaying multiple validation errors from a form submission.
+ + + +flash()->error('The email field is required.');
+flash()->error('Password must be at least 8 characters.');
+flash()->error('Please accept the terms and conditions.');
+ E-commerce interactions
+Shows notifications for adding items to cart with stock warnings and promotions.
+ + + +flash()->success('iPhone 15 Pro added to cart!');
+flash()->warning('Only 2 items left in stock!');
+flash()->info('Add $20 more for free shipping!');
+ Upload progress and status
+Demonstrates file upload progress with success and additional info.
+ + + +flash()->success('document.pdf uploaded successfully!');
+flash()->info('File size: 2.4 MB');
+ Preferences updated
+Shows settings save confirmation with additional context.
+ + + +flash()->success('Settings saved successfully!');
+flash()->info('Some changes may require a page refresh.');
+ Transaction completed
+Payment confirmation with order details and receipt notification.
+ + + +flash()->success('Payment of $149.99 confirmed!');
+flash()->info('Order #12345 - Receipt sent to your email.');
+ Transaction declined
+Payment failure with helpful guidance for resolving the issue.
+ + + +flash()->error('Payment declined by your bank.');
+flash()->warning('Please try a different payment method.');
+flash()->info('Your cart has been saved.');
+ SweetAlert dialog
+Uses SweetAlert for a confirmation dialog before deleting.
+ + + +sweetalert()
+ ->showCancelButton()
+ ->confirmButtonText('Yes, delete it!')
+ ->cancelButtonText('Cancel')
+ ->warning('Are you sure? This cannot be undone.');
+ Timeout warning
+Alerts user when their session is about to expire.
+ + + +flash()->warning('Your session will expire in 5 minutes.');
+flash()->info('Click anywhere to stay logged in.');
+ + PHPFlasher makes it easy to add elegant notifications to your Laravel application. + Try the quick demos below! +
+ + {{-- Quick Demo Buttons --}} +Success, error, warning, and info notifications for every use case.
+Material, iOS, Slack, Amazon, and many more beautiful themes.
+Toastr, SweetAlert, Noty, and Notyf adapters included.
+Place notifications anywhere on the screen.
+User registration, shopping cart, payments, and more.
+Build and customize notifications in real-time.
+Get started with PHPFlasher in seconds. Just install and use!
+ +composer require php-flasher/flasher-laravel
+ // In your controller
+flash()->success('Profile updated successfully!');
+
+// With options
+flash()->success('Welcome back!', [
+ 'position' => 'top-right',
+ 'timeout' => 5000,
+]);
+
+// Using themes
+flash()->use('theme.material')->info('New feature available!');
+ + Explore the interactive playground to customize notifications and see the generated code. +
+ + + Open Playground + +PHPFlasher works seamlessly with Laravel Livewire. See live examples below.
+Simple state management
+class Counter extends Component
+{
+ public int $count = 0;
+
+ public function increment(): void
+ {
+ $this->count++;
+ flash()->success("Count increased to {$this->count}!");
+ }
+
+ public function decrement(): void
+ {
+ $this->count--;
+ flash()->warning("Count decreased to {$this->count}");
+ }
+
+ public function reset(): void
+ {
+ $this->count = 0;
+ flash()->info('Counter has been reset.');
+ }
+}
+ Form validation example
+class ContactForm extends Component
+{
+ public string $name = '';
+ public string $email = '';
+ public string $message = '';
+
+ protected $rules = [
+ 'name' => 'required|min:2',
+ 'email' => 'required|email',
+ 'message' => 'required|min:10',
+ ];
+
+ public function submit(): void
+ {
+ $this->validate();
+
+ // Process form...
+
+ flash()->success('Message sent successfully!');
+ flash()->info('We will respond within 24 hours.');
+
+ $this->reset(['name', 'email', 'message']);
+ }
+}
+ Handle dialog responses in Livewire
+class DeleteItem extends Component
+{
+ protected $listeners = [
+ 'sweetalert:confirmed' => 'onConfirmed',
+ 'sweetalert:denied' => 'onDenied',
+ ];
+
+ public function confirmDelete(): void
+ {
+ sweetalert()
+ ->showDenyButton()
+ ->showCancelButton()
+ ->confirmButtonText('Yes, delete!')
+ ->denyButtonText('Keep it')
+ ->warning('Delete this item?');
+ }
+
+ public function onConfirmed(array $payload): void
+ {
+ // Delete the item...
+ flash()->success('Item deleted!');
+ }
+
+ public function onDenied(array $payload): void
+ {
+ flash()->info('Item was kept.');
+ }
+}
+ <div>
+ <button wire:click="confirmDelete"
+ class="btn btn-danger">
+ Delete Item
+ </button>
+</div>
+ composer require php-flasher/flasher-laravel
+ public function save()
+{
+ // Your logic...
+ flash()->success('Saved!');
+}
+ PHPFlasher automatically detects Livewire requests and handles them appropriately. No additional configuration needed!
+2.4 MB - Modified today
+Build and customize notifications in real-time. See the generated PHP code instantly.
+flash()->success('Operation completed successfully!');
+ Operation completed successfully!
+This is a static preview. Click "Show Notification" to see the real notification.
+Place your notifications anywhere on the screen. Click any position to see it in action.
+Set the position directly when creating a notification.
+flash()
+ ->option('position', 'top-left')
+ ->success('Profile updated!');
+
+// Or use the fluent method
+flash()
+ ->position('bottom-right')
+ ->info('New message received!');
+ Set a default position for all notifications in your config file.
+return [
+ 'default' => 'flasher',
+ 'options' => [
+ 'position' => 'bottom-right',
+ ],
+];
+ top-lefttop-centertop-right (default)center-leftcentercenter-rightbottom-leftbottom-centerbottom-rightChoose from 17+ beautiful themes to match your application's design.
+{{ $theme['desc'] }}
+Apply themes to your notifications with the use() method.
// Use a specific theme
+flash()->use('theme.material')->success('Material design notification!');
+
+// Different themes for different messages
+flash()->use('theme.ios')->info('iOS style notification');
+flash()->use('theme.slack')->warning('Slack style warning');
+flash()->use('theme.amazon')->success('Amazon style success');
+
+// Set default theme in config/flasher.php
+return [
+ 'default' => 'theme.material',
+];
+ PHPFlasher supports four notification types for different scenarios.
+Positive feedback
+Use success notifications for completed actions, confirmations, and positive feedback.
+ +flash()->success('Profile updated successfully!');
+
+// With title
+flash()->success('Welcome aboard!', 'Account Created');
+ Failures and issues
+Use error notifications for validation failures, server errors, and problems.
+ +flash()->error('Invalid credentials.');
+
+// With title
+flash()->error('Please try again.', 'Payment Failed');
+ Caution alerts
+Use warning notifications to alert users about potential issues or important notices.
+ +flash()->warning('Session expiring soon.');
+
+// With title
+flash()->warning('Only 2 left!', 'Low Stock');
+ Neutral information
+Use info notifications for tips, updates, and general information.
+ +flash()->info('New version available!');
+
+// With title
+flash()->info('Use shortcuts!', 'Pro Tip');
+ PHPFlasher supports multiple notification libraries. Choose your favorite!
+Default adapter with 17+ themes
+The default PHPFlasher adapter with beautiful built-in themes. No additional JavaScript libraries required.
+ +composer require php-flasher/flasher-symfony
+ flash()->success('Operation completed!');
+ Simple, elegant toast notifications
+Classic toast notifications with smooth animations. One of the most popular notification libraries.
+ +composer require php-flasher/flasher-toastr-symfony
+ toastr()->success('Data saved successfully!');
+
+// With options
+toastr()
+ ->closeButton()
+ ->progressBar()
+ ->positionClass('toast-top-right')
+ ->success('Profile updated!');
+ Beautiful, responsive, customizable alerts
+Feature-rich modal dialogs with confirmations, inputs, and beautiful animations. Perfect for important user interactions.
+ +composer require php-flasher/flasher-sweetalert-symfony
+ sweetalert()->success('Great job!', 'Success');
+
+// Confirmation dialog
+sweetalert()
+ ->showDenyButton()
+ ->showCancelButton()
+ ->confirmButtonText('Save')
+ ->denyButtonText("Don't save")
+ ->warning('Do you want to save the changes?');
+ Dependency-free notification library
+A flexible, dependency-free notification library with multiple layouts and themes.
+ +composer require php-flasher/flasher-noty-symfony
+ noty()->success('Data saved!');
+
+// With layout options
+noty()
+ ->layout('topCenter')
+ ->timeout(3000)
+ ->progressBar()
+ ->info('Processing your request...');
+ Minimalist, responsive notifications
+A minimalist JavaScript library for toast notifications. Tiny footprint with smooth animations.
+ +composer require php-flasher/flasher-notyf-symfony
+ notyf()->success('Minimal and clean!');
+
+// With options
+notyf()
+ ->position('x', 'right')
+ ->position('y', 'top')
+ ->dismissible(true)
+ ->ripple(true)
+ ->success('File uploaded successfully!');
+