{"id":13828322,"url":"https://github.com/spatie/laravel-flash","last_synced_at":"2025-05-14T04:07:50.352Z","repository":{"id":50361355,"uuid":"175572658","full_name":"spatie/laravel-flash","owner":"spatie","description":"A lightweight package to flash messages","archived":false,"fork":false,"pushed_at":"2025-02-21T09:38:58.000Z","size":85,"stargazers_count":603,"open_issues_count":0,"forks_count":31,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-14T03:57:22.768Z","etag":null,"topics":["flash","laravel","message","php"],"latest_commit_sha":null,"homepage":"https://freek.dev/1291-a-laravel-package-to-flash-messages","language":"PHP","has_issues":true,"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/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2019-03-14T07:44:52.000Z","updated_at":"2025-04-09T20:52:07.000Z","dependencies_parsed_at":"2024-06-18T11:41:31.518Z","dependency_job_id":"af9e7ada-fa5a-4690-aecb-cb800ef9e273","html_url":"https://github.com/spatie/laravel-flash","commit_stats":{"total_commits":107,"total_committers":14,"mean_commits":7.642857142857143,"dds":"0.26168224299065423","last_synced_commit":"46be04635bd1820bc7631abd6108128719ee5e10"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-flash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-flash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-flash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-flash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-flash/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254069453,"owners_count":22009557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["flash","laravel","message","php"],"created_at":"2024-08-04T09:02:41.325Z","updated_at":"2025-05-14T04:07:50.314Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"# A lightweight package to flash messages\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-flash.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-flash)\n![run-tests](https://github.com/spatie/laravel-flash/workflows/run-tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-flash.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-flash)\n\nThis is a lightweight package to send flash messages in Laravel apps.  A flash message is a message that is carried over to the next request by storing it in the session. This package only supports one single flash message at a time.\n\nThis is how it can be used:\n\n```php\nclass MySpecialSnowflakeController\n{\n    public function store()\n    {\n        // …\n\n        flash('My message', 'my-class');\n\n        return back();\n    }\n}\n```\n\nIn your view you can do this:\n\n```blade\n@if (flash()-\u003emessage)\n    \u003cdiv class=\"{{ flash()-\u003eclass }}\"\u003e\n        {{ flash()-\u003emessage }}\n    \u003c/div\u003e\n@endif\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-flash.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-flash)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-flash\n```\n\n## Usage\n\nHere is an example on how to flash a message.\n\n```php\nclass MyController\n{\n    public function store()\n    {\n        // …\n\n        flash('My message');\n\n        return back();\n    }\n}\n```\n\nIn your view you can use it like this\n\n```blade\n@if(flash()-\u003emessage)\n    \u003cdiv\u003e\n        {{ flash()-\u003emessage }}\n    \u003c/div\u003e\n@endif\n```\n\n### Using a class name to style the displayed message\n\nYou can add a class as the second parameter. This is typically used to style the output in your HTML.\n\n```php\nclass MyController\n{\n    public function store()\n    {\n        // …\n\n        flash('My message', 'my-class');\n\n        return back();\n    }\n}\n```\n\nIn your view you can use the class like this:\n\n```blade\n@if (flash()-\u003emessage)\n    \u003cdiv class=\"{{ flash()-\u003eclass }}\"\u003e\n        {{ flash()-\u003emessage }}\n    \u003c/div\u003e\n@endif\n```\n\nYou can also set an array of classes. These will be output by `flash()-\u003eclass` by imploding the array with a space-delimiter.\n\n```php\nflash('My message', ['my-class', 'another-class']); // flash()-\u003eclass output is: 'my-class another-class'\n```\n\n### Adding your own methods\n\nIf you don't want to specify a class each time you flash a message you can add a method name to `flash`.\n\nThe easiest way is by passing an array to the `levels` method. The key is the method name that should be added to `flash()`. The value is the class that will automatically be used when rendering the message.\n\n```php\n// this would probably go in a service provider\n\n\\Spatie\\Flash\\Flash::levels([\n    'success' =\u003e 'alert-success',\n    'warning' =\u003e 'alert-warning',\n    'error' =\u003e 'alert-error',\n]);\n```\n\nThe above example will make these methods available on `flash`:\n\n```php\nflash()-\u003esuccess('Hurray');\nflash()-\u003ewarning('Mayybeee');\nflash()-\u003eerror('Oh Oh');\n```\n\nThe most likely scenario is that you want to consume the flash message in a view. You can use the `message`, `class` and `level` properties on the view.\n\n```blade\n@if (flash()-\u003emessage)\n    \u003cdiv class=\"{{ flash()-\u003eclass }}\"\u003e\n        {{ flash()-\u003emessage }}\n    \u003c/div\u003e\n\n    @if(flash()-\u003elevel === 'error')\n        This was an error.\n    @endif\n@endif\n```\n\nAdditionally, when you've added your own method, you can also pass that method name as a second parameter to `flash` itself:\n\n```php\nflash('Hurray', 'success'); // `flash()-\u003eclass` will output 'alert-success'\n```\n\nYou can also add a method to `flash` by using `macro`.\n\nHere's an example:\n\n```php\n// this would probably go in a service provider\n\nuse Spatie\\Flash\\Message;\n\n\\Spatie\\Flash\\Flash::macro('warning', function (string $message) {\n    return $this-\u003eflashMessage(new Message($message, 'alert alert-warning'));\n});\n```\n\nYou can now use a `warning` method on `flash`:\n\n```php\nflash()-\u003ewarning('Look above you!');\n```\n\nYou can pass the desired `level` as the third argument to `Message`.\n\n```php\n// in a service provider\nuse Spatie\\Flash\\Message;\n\n\\Spatie\\Flash\\Flash::macro('warning', function (string $message) {\n    return $this-\u003eflashMessage(new Message($message, 'alert alert-warning', 'my-level'));\n});\n\n// in the next request, after having flashed a message \nflash()-\u003elevel; // returns `my-level`\n```\n\n## Alternatives\n\nThis package is intended to be lightweight. If you need things like multiple messages, support for Bootstrap, overlays, ... take a look at [this excellent flash package](https://github.com/laracasts/flash) by [Jeffrey Way](https://github.com/JeffreyWay) or [Laraflash](https://github.com/coderello/laraflash) by [Ilya Sakovich](https://github.com/hivokas).\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n### Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-flash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-flash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-flash/lists"}