rzl-app/laravel-toaster

Generates a Laravel Toaster as Sessions Flash or Props an Array for your Blade or Front-End Api.

v1.0.2 2025-07-05 21:10 UTC

This package is auto-updated.

Last update: 2025-07-05 21:12:18 UTC


README

    __        __              _                  _______
    \ \      / /__  _ __ ___  | |_ ___  ___ ___  \      \   ___ ___  ___
     \ \ /\ / / _ \| '__/ _ \ | __/ _ \/ __/ __| /   |   \ / __/ _ \/ __|
      \ V  V / (_) | | |  __/ | ||  __/\__ \__ \ /    |    \ (_|  __/\__ \
       \_/\_/ \___/|_|  \___|  \__\___||___/___/ \____|__  /\___\___||___/
                                                        \/          \/
                      🚀 Rzl App Laravel Toaster 🚀

A clean, powerful Laravel Session Flash & Props Toaster helper —
perfect for Blade, Vue, React, Inertia, Livewire, or plain API.
Built with ❤️ by @rzl-app.

Latest Version Coverage PHPStan Downloads

🛠 Requirements

Laravel PHP Package
>=9.x >=8.1 Ver 1.x

⚙️ Installation

composer require rzl-app/laravel-toaster

Publish config

php artisan vendor:publish --tag="RzlLaravelToaster"

Will create config/rzl-laravel-toaster.php:

return [
  /*
  |--------------------------------------------------------------------------
  | Session Flash Name for Toaster
  |--------------------------------------------------------------------------
  |
  | This defines the session key name used to flash the toaster data.
  | It will be retrieved on the frontend after a redirect or page reload.
  |
  | Note: The Value must be string and not empty or only space or as blank
  |       value, if invalid value will return fallback as "toast".
  |
  | Default: 'toast'
  |
  | Example:
  | session()->flash('toast', [...]);
  |
  */
  'session_name'  => "toast",

  /*
  |--------------------------------------------------------------------------
  | Settings Toaster Options As Session Flash or Only Return As Props Array.
  |--------------------------------------------------------------------------
  |
  | Toaster Mode: Flash Session or Return as Props Array
  | Return Format:
  |  false: `Session` -> `session()->flash("toast", [$title, $message, $type, $durationClose]);`
  |   true: Props json output or array.
  |
  */
  'as_prop'       => false,
];

🚀 Usage

✅ Basic flash

toaster('Profile saved!');

🚀 With type & timeout

toaster('Unauthorized action!', 'error', 5000);
toaster('Heads up!', 'warning', 0); // No auto close

🪄 Shortcuts

toasterSuccess('Data saved!');
toasterError('Something wrong...');
toasterInfo('Heads up!');
toasterWarning('Careful!');

🔥 Props for API / SPA

return [
    'toast' => toasterAsProps('Welcome back!', 'info')
];

or shortcuts:

return response()->json([
    'toast' => toasterErrorAsProps('Invalid data!')
]);

🖥 Blade Example

@if(session('toast'))
  <script>
    window.toast = @json(session('toast'));
    console.log('Toast:', window.toast);
  </script>
@endif

🚀 JSON output

{
  "title": "success_1725459999",
  "message": "Profile updated",
  "type": "success",
  "durationClose": 2000,
  "timeGenerate": 1725459999
}

💡 Tips & Best Practice

✅ Use session for simple Laravel + Blade / Livewire.
✅ Use props for Inertia, SPA, or pure API.
✅ Set as_prop true in config to force always JSON array.

❤️ Sponsor this package

Help support development:

👉 Become a sponsor

📝 Changelog

See CHANGELOG.

🤝 Contributing

See CONTRIBUTING.

🛡 Security

Please report issues to rizalvindwiky@gmail.com.

🙌 Credits

📜 License

The MIT License (MIT). Please see License File for more information.