{"id":20326512,"url":"https://github.com/slackerzz/laravel-flashmessages","last_synced_at":"2026-03-08T06:32:05.141Z","repository":{"id":78435661,"uuid":"490042686","full_name":"slackerzz/laravel-flashmessages","owner":"slackerzz","description":"Add flash messages (alerts) to your Laravel project.","archived":false,"fork":false,"pushed_at":"2022-05-08T20:00:09.000Z","size":315,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T10:45:42.593Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slackerzz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wadeshuler"}},"created_at":"2022-05-08T20:00:01.000Z","updated_at":"2022-05-05T13:27:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"84503508-8188-461f-a6e4-75f816f659e2","html_url":"https://github.com/slackerzz/laravel-flashmessages","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/slackerzz/laravel-flashmessages","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slackerzz%2Flaravel-flashmessages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slackerzz%2Flaravel-flashmessages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slackerzz%2Flaravel-flashmessages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slackerzz%2Flaravel-flashmessages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slackerzz","download_url":"https://codeload.github.com/slackerzz/laravel-flashmessages/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slackerzz%2Flaravel-flashmessages/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30247349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T05:41:50.788Z","status":"ssl_error","status_checked_at":"2026-03-08T05:41:39.075Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T19:44:23.367Z","updated_at":"2026-03-08T06:32:05.093Z","avatar_url":"https://github.com/slackerzz.png","language":null,"funding_links":["https://github.com/sponsors/wadeshuler"],"categories":[],"sub_categories":[],"readme":"# Laravel Flash Messages\n\nAdd flash messages (alerts) to your Laravel project. Supports Tailwind v2, Bootstrap v4, Bootstrap v5, or any custom CSS you need.\n\nThis was built and tested on Laravel 8. So far it has not been tested on Laravel 7. If you try it, please let me know how it goes so I can update this readme :)\n\n## Screenshots\n\n### Laravel 8 with Breeze and Tailwind v2\n![](.github/images/ScreenShot-Laravel-8-Breeze-Tailwind-v2.png)\n\n### Laravel 8 with [AdminLTE](https://github.com/jeroennoten/Laravel-AdminLTE) and Bootstrap v4\n![](.github/images/ScreenShot-AdminLTE-Bootstrap-v4.png)\n\n## Table of Contents\n\n - [Warning](#warning)\n - [Installation](#installation)\n   - [Tailwind v2](#tailwind-v2)\n   - [Bootstrap v4](#bootstrap-v4)\n   - [Bootstrap v5](#bootstrap-v5)\n   - [Other CSS Templating](#other-css-templating)\n - [Installing Icons](#installing-icons)\n   - [Install FontAwesome via CDN](#install-fontawesome-via-cdn)\n   - [Install FontAwesome via NPM](#install-fontawesome-via-npm)\n - [Info about the view files](#info-about-the-view-files)\n - [Usage](#usage)\n   - [Safely using user input/data](#safely-using-user-inputdata)\n - [Advanced Usage](#advanced-usage)\n   - [Helper Functions](#helper-functions)\n   - [Using HTML inside the message](#using-html-inside-the-message)\n   - [Creating a new type](#creating-a-new-type)\n   - [Individual Message Custom Configuration](#individual-message-custom-configuration)\n   - [How to see the messages to modify the view files?](#how-to-see-the-messages-to-modify-the-view-files?)\n\n## Warning\n\nI want to ensure you see this warning message, which is why it is first and before the installation instructions.\n\n**The `icon` and `message` will NOT be escaped/encoded.**\n\nFor the icon, this shouldn't be a problem since they are generated from the config and are an array map. However, you should be aware of it just in case you do (for some crazy reason) use user input in the icon passed to the individual message's config array.\n\nFor the message, in most cases, it shouldn't be a problem. This allows you to use HTML inside of the message itself, so you can include a link, underline or bold something, make a list, whatever you need.\n\nYou can use a user's data that is generated by your application, like their user id.\n\nIf, for some crazy reason, you do need to pass user input into the message, you SHOULD encode it using Laravel's `e()` helper function. Not the whole message, just the individual pieces of data you are inserting into it, like their name. If it's questionable, encode it. Read:[https://laravel.com/docs/8.x/blade#html-entity-encoding](https://laravel.com/docs/8.x/blade#html-entity-encoding)\n\nMaybe there is a better way to handle this? I am fairly new to Laravel, so I am open to suggestions so we can do away with this warning.\n\n## Installation\n\nTo install this package, run:\n\n```\ncomposer require wadeshuler/laravel-flashmessages\n```\n\nPlace the code for the container component where you want the flash messages to appear.\n\n```php\n\u003cx-flashmessages-container /\u003e\n```\n\n**Note:** If you want to display the flash messages on multiple different types of layouts, you will want to leave it alone and wrap a `\u003cdiv\u003e` around the call to the component. This way you can use a different wrapper on your login/register pages and your dashboard.\n\nExample:\n\n```php\n\u003cdiv class=\"auth-page-alert-wrapper\"\u003e\n    \u003cx-flashmessages-container /\u003e\n\u003c/div\u003e\n```\n\nand\n\n```php\n\u003cdiv class=\"dashboard-alert-wrapper\"\u003e\n    \u003cx-flashmessages-container /\u003e\n\u003c/div\u003e\n```\n\nThis package supports Tailwind v2 (comes with Laravel 8 by default), Bootstrap v4, and Bootstrap v5 out of the box.\n\nDue to this flexibility, we can't load an appropriate config or view files by default. So you will get an error if you do not install them.\n\nFollow the instructions below for the appropriate CSS environment you are using.\n\n### Tailwind v2\n\nInstall the config file:\n\n```\nphp artisan vendor:publish --provider=\"wadeshuler\\FlashMessages\\FlashMessagesProvider\" --tag=\"tailwind2-config\"\n```\n\nInstall the view files:\n\n```\nphp artisan vendor:publish --provider=\"wadeshuler\\FlashMessages\\FlashMessagesProvider\" --tag=\"tailwind2-views\"\n```\n\n### Bootstrap v4\n\nInstall the config file:\n\n```\nphp artisan vendor:publish --provider=\"wadeshuler\\FlashMessages\\FlashMessagesProvider\" --tag=\"bootstrap4-config\"\n```\n\nInstall the view files:\n\n```\nphp artisan vendor:publish --provider=\"wadeshuler\\FlashMessages\\FlashMessagesProvider\" --tag=\"bootstrap4-views\"\n```\n\n### Bootstrap v5\n\nInstall the config file:\n\n```\nphp artisan vendor:publish --provider=\"wadeshuler\\FlashMessages\\FlashMessagesProvider\" --tag=\"bootstrap5-config\"\n```\n\nInstall the view files:\n\n```\nphp artisan vendor:publish --provider=\"wadeshuler\\FlashMessages\\FlashMessagesProvider\" --tag=\"bootstrap5-views\"\n```\n\n### Other CSS Templating\n\nIf you are not using Bootstrap or Tailwind, then just pick any of them and modify the generated files however you need.\n\nIn the future when newer versions of Tailwind or Bootstrap are out, just choose the latest appropriate version and modify it if necessary. Depending on how much the future versions change, depends on how much you have to modify.\n\n## Installing Icons\n\nA stock Laravel 8 installation does not include FontAwesome, so the icons will not work. You are free to use whatever icons you want, you will just have to modify the config to use them. If you are using a 3rd party template of some kind, ensure that FontAwesome isn't already installed. You can simply try using an icon on a view file somewhere.\n\nIf you want to use FontAwesome, you must first install it. You have 2 options, CDN or NPM :)\n\n### Install FontAwesome via CDN\n\nIn all of the layouts you want to use flash messages on, add the stylesheet to the head section:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css\" integrity=\"sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==\" crossorigin=\"anonymous\" /\u003e\n```\n\nThen add the corresponding JavaScript file just before the closing body tag:\n\n```html\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js\" integrity=\"sha512-RXf+QSDCUQs5uwRKaDoXt55jygZZm2V++WUZduaU/Ui/9EGp3f/2KZVahFZBKGH0s774sd3HmrhUy+SgOFQLVQ==\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\n```\n\n### Install FontAwesome via NPM\n\n```\nnpm install @fortawesome/fontawesome-free --save-dev\n```\n\nThen import it in your `resources/css/app.css` file:\n\n```css\n@import '@fortawesome/fontawesome-free/css/fontawesome';\n```\n\nRequire it in your `resources/js/app.js` file:\n\n```js\nrequire(\"@fortawesome/fontawesome-free/js/all\");\n```\n\nFinally, run:\n\n```\nnpm run dev\n```\n\n## Info about the view files\n\nThe view files will be published to `resources/views/vendor/flashmessages`.\n\n**The container component blade file:** It is a container that holds the individual flash messages. It simply loops through all the flash messages and loads them each into their own components.\n\n**The message component blade file:** The template for each flash message itself. There are a few helper functions available to assist with generating the message. Use the helper functions and do not echo the variables directly. The helper functions return an empty string if the value is not set (null).\n\n\n## Usage\n\nA Composer alias is made for the FlashMessages Facade so you don't have to import it manually, but you still can.\n\nUse the backslash and you don't have to import it: `\\FlashMessages::addFlashMessage($type, $message)`\n\nOr, you can import it at the top of your class simply as: `use \\FlashMessages;`\n\nOr, you can import it like you do for everything else as: `use wadeshuler\\FlashMessages\\Facades\\FlashMessages;`\n\nNow all you have to do is add the flash message:\n\n```php\n\\FlashMessages::addFlashMessage(\n    'success',\n    'This is a success message!',\n);\n```\n\nYou can also use the `flash()` macro on a redirect in your controller:\n\nExample:\n\n```php\nreturn redirect(route('home'))-\u003eflash('success', 'This is a success message!', ['dismissable' =\u003e false]);\n```\n\nThis will probably be the preferred method to use, unless you need to add more than 1 flash message.\n\n### Safely using user input/data\n\nPlease read the big warning that is at the beginning of this README. The message is not encoded by blade's `{{ $message }}` rendering tags. The message is rendered using `{!! $message !!}` so HTML can be used.\n\nIf you need to pass user data into the message, here is how you can safely do it:\n\n```php\n\\FlashMessages::addFlashMessage(\n    'success',\n    'Thank you ' . e($user-\u003ename) . ' for your payment!',\n);\n```\n\n## Advanced Usage\n\n### Add Flash Message Now\n\nIn addition to the `addFlashMessage()`, there is also `addFlashMessageNow()` to render messages for immediate use. It\nutilizes Laravel's `request()-\u003esession()-\u003enow()`, which allows you to add a flash message and display it on the same\npage load.\n\nI added this because I wanted to convert the built in status messages to nice Bootstrap alerts (flash messages). For\nexample: When email verification is enabled, Laravel returns a `verification-link-sent` status. This isn't very easy\nto work with. At this point, the page has already loaded and or been redirected to wherever it's supposed to go. Since\nthe page has already loaded, if we use `addFlashMessage()` at this point, the flash message will display on this page\nload AND the next. That is a problem, the message shouldn't be shown on the next subsequent page.\n\nTo solve this, we can use `addFlashMessageNow()` instead:\n\n```php\n\\FlashMessages::addFlashMessageNow(\n    'success',\n    'A verification link has been emailed to you!',\n);\n```\n\nI wrote a middleware that simply detects all of the generic Laravel and Fortify \"statuses\" and converts them to flash\nmessages, with two separate arrays for regular flash messages, and ones that should be called with \"now\". I plan on\nadding it to this package later.\n\n### Helper Functions\n\nThere is 1 app level helper function to determine if there are any flash messages. This is useful if you have wrapped the call to the component with a div and it is creating spacing issues.\n\n```php\n@if ( hasFlashMessages() )\n    \u003cdiv class=\"my-2 mx-4\"\u003e\n        \u003cx-flashmessages-container /\u003e\n    \u003c/div\u003e\n@endif\n```\n\nThere are also 9 `FlashMessages` helpers available for use within the `resources/views/vendor/flashmessages/components/message.blade.php` file. You can see an example of most of these inside this blade file.\n\n - `isDismissable()` - (bool) Determine if the flash message is dismissable.\n - `getClass()` - Get the class name determined from `typeToClassMap` or the default if unknown.\n - `shouldShowIcon()` - (bool) Determine if the icon should be shown.\n - `getIcon()` - Get the icon determined from `typeToIconMap` or default if unknown.\n - `shouldShowTitle()` - (bool) Determine if the title should be shown.\n - `hasTitle()` - (bool) Determine if the flash message has a title.\n - `getTitle()` - Get the title.\n - `hasMessage()` - Determine if the flash message has a message (it should, but added just in case).\n - `getMessage()` - Get the message.\n\n### Using HTML inside the message\n\nYou can pass HTML to the message if you need to.\n\nHere is how you can pass a link in the message:\n\n```php\n\\FlashMessages::addFlashMessage(\n    'error',\n    'Your subscription has expired. Click \u003ca href=\"https://www.google.com\" class=\"alert-link\"\u003ehere\u003c/a\u003e to renew!',\n);\n```\n\n**Note:** `alert-link` is a Bootstrap class that makes the link color match the type/color of the alert. It isn't necessary if you aren't using Bootstrap. If you use Bootstrap and create your own custom types, you may want to also create the CSS for these as well.\n\n### Creating a new type\n\nCreating a new type is very easy.\n\nAdd your icon's HTML to the `typeToIconMap` array in `config/flashmessages.php`:\n\n```php\n'typeToIconMap' =\u003e [\n    'foo' =\u003e '\u003ci class=\"fab fa-fw fa-apple mr-2\"\u003e\u003c/i\u003e',\n],\n```\n\nFor FontAwesome, I like to use the `fa-fw` class. This makes the icons all have the same width and it looks better overall. Especially when you show multiple messages on the screen.\n\nThen add your class to the `typeToClassMap` array, also in `config/flashmessages.php`:\n\n```php\n'typeToClassMap' =\u003e [\n    'foo' =\u003e 'custom-class',\n],\n```\n\n**Note:** If you are using Bootstrap, the class will be added to the alert prefix as `alert-custom-class`\n\nDon't forget to create the CSS for your custom class:\n\n```css\n.alert-custom-class {\n    color: #fff;\n    background: #673ab7;\n    border-color: #552d9c;\n}\n\n.alert-custom-class .alert-link {\n    color: #b8ebff;\n    text-decoration: none;\n}\n```\n\nAdd your hover/active/visited effects if you want. You may be using mix or SASS instead of CSS. Do it properly and not a custom hack by throwing a style tag in the layout... Don't forget to run `npm run dev` if you need to, to re-compile the CSS you just added.\n\n### Individual Message Custom Configuration\n\nThe `addFlashMessage()` method supports a 3rd argument, a `$config` array. Most of the available options can be passed to the individual message's config array. However, you can not pass `message`, `typeToIconMap`, or `typeToClassMap`.\n\nExample:\n\n```php\n\\FlashMessages::addFlashMessage(\n    'success',\n    'This is a highly configured success message!',\n    [\n        // common config options\n        'title' =\u003e 'Custom Title',\n        'class' =\u003e 'custom-classname',           // if you want to use a different class for this message\n        'icon'  =\u003e '\u003ci class=\"fas fa-fw fa-taxi\"\u003e\u003c/i\u003e',// if you want to use a different icon for this message\n\n        // rare config options (set in default config and rarely have to change)\n        'showIcon'    =\u003e true,                   // override the default config values\n        'showTitle'   =\u003e false,                  // override the default config values\n        'dismissable' =\u003e false,                  // override the default config values\n\n        // In the VERY RARE event you need to override the \"forced\" settings (defined in config)\n        // This allows you to override the override for this individual message itself\n\n        // very rare config options\n        'forceIcon' =\u003e false,                    // override `forceIcon` (if enabled in config)\n        'forceTitle'  =\u003e false,                  // override `forceTitle` (if enabled in config)\n        'forceDismissable'  =\u003e false,            // override `forceDismissable` (if enabled in config)\n    ],\n);\n```\n\n\n## How to see the messages to modify the view files?\n\nIn order to edit the container or the message view files, you probably will need to be able to see at least 1 flash message so you can test it.\n\nCreate a route:\n\n```php\nRoute::get('/redirect-test', [App\\Http\\Controllers\\Controller::class, 'redirectTest'])-\u003ename('redirect.test');\n```\n\nChange `Controller` to an appropriate controller. Any one will do, but probably whichever one is your main controller that renders your dashboard.\n\nAdd the test function to that controller:\n\n```php\npublic function redirectTest(\\Request $request)\n{\n    \\FlashMessages::addFlashMessage(\n        'success',\n        'This is a success message!',\n    );\n\n    \\FlashMessages::addFlashMessage(\n        'warning',\n        'This is a warning message!',\n    );\n\n    \\FlashMessages::addFlashMessage(\n        'info',\n        'This is an info message!',\n    );\n\n    \\FlashMessages::addFlashMessage(\n        'error',\n        'This is an error message!',\n        [\n            'title' =\u003e 'Custom Error Title',\n            'dismissable' =\u003e false,\n        ]\n    );\n\n    // Let's also ensure a message with an undefined type looks fine while we are here\n    \\FlashMessages::addFlashMessage(\n        'foo',                              // some type that does not exist, falls back to default class/icon\n        'This is an error message!',\n    );\n\n    return redirect(route('home'));     // change home to whatever named route you need (ie: dashboard)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslackerzz%2Flaravel-flashmessages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslackerzz%2Flaravel-flashmessages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslackerzz%2Flaravel-flashmessages/lists"}