Skip to content

The main repository for PHPFlasher, a PHP library that makes it easy to add customizable notification messages to your web applications. Supports Laravel, Symfony, and standalone use. This monorepository enables efficient collaboration and version control among developers.

License

Notifications You must be signed in to change notification settings

php-flasher/php-flasher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPFlasher Logo

Author Badge Source Code Badge GitHub Release Badge License Badge Packagist Downloads Badge GitHub Stars Badge Supported PHP Version Badge

Table of Contents

About PHPFlasher

PHPFlasher is an open-source tool that helps you add flash messages to your web applications. Flash messages are short notifications that provide feedback to users after they perform actions, such as submitting a form or encountering an error. These messages enhance the user experience by informing users about the outcomes of their actions.

PHPFlasher simplifies the process of integrating flash messages into Laravel and Symfony projects. It uses sessions to store messages, allowing you to set a message on one page and display it on another without complex setup.

Features

  • Multiple Adapters: Supports Laravel, Symfony, Toastr, Noty, SweetAlert, and more.
  • Flexible Configuration: Customize the appearance and behavior of flash messages.
  • Extensible: Easily integrate with various frontend libraries and frameworks.
  • Intuitive API: Simple functions to create and manage flash messages.

Supported Versions

PHPFlasher Version PHP Version Symfony Version Laravel Version
v2.x ≥ 8.2 ≥ 7.2 ≥ 11
v1.x ≥ 5.3 ≥ 2.0 ≥ 4.0

Note: If your project uses PHP, Symfony, or Laravel versions below the requirements for PHPFlasher v2.x, please use PHPFlasher v1.x.

Installation

Core Package

Install the core PHPFlasher package via Composer:

  • For Laravel:

    composer require php-flasher/flasher-laravel

    After installation, set up the necessary assets:

    php artisan flasher:install

    Note: PHPFlasher automatically injects the necessary JavaScript and CSS assets into your Blade templates. No additional steps are required for asset injection.

  • For Symfony:

    composer require php-flasher/flasher-symfony

    After installation, set up the necessary assets:

    php bin/console flasher:install

    Note: PHPFlasher automatically injects the necessary JavaScript and CSS assets into your Twig templates. No additional steps are required for asset injection.

Adapters

PHPFlasher provides various adapters for different frameworks and notification libraries. Below is an overview of available adapters:

Toastr

Noty

Notyf

SweetAlert

For detailed installation and usage instructions for each adapter, refer to their respective README.md.

Quick Start

To display a notification message, you can either use the flash() helper function or obtain an instance of flasher from the service container. Then, before returning a view or redirecting, call the desired method (success(), error(), etc.) and pass in the message to be displayed.

Using the flash() Helper

class BookController
{
    public function saveBook()
    {
        // Your logic here

        flash('Your changes have been saved!');

        return redirect()->back();
    }
}

Using the flasher Service

use Flasher\Prime\FlasherInterface;

class AnotherController
{
    /**
     * If you prefer to use dependency injection
     */
    public function register(FlasherInterface $flasher)
    {
        // Your logic here
        
        $flasher->success('Your changes have been saved!');

        // ... redirect or render the view
    }

    public function update()
    {
        // Your logic here

        app('flasher')->error('An error occurred while updating.'); // ony for laravel

        return redirect()->back();
    }
}

Usage Examples

Success Message

flash()->success('Operation completed successfully!');

Error Message

flash()->error('An error occurred.');

Info Message

flash()->info('This is an informational message.');

Warning Message

flash()->warning('This is a warning message.');

Passing Options

flash()->success('Custom message with options.', ['timeout' => 3000, 'position' => 'bottom-left']);

Adapters Overview

PHPFlasher supports various adapters to integrate seamlessly with different frameworks and frontend libraries. Below is an overview of available adapters:

Adapter Repository Description
flasher-laravel Laravel framework adapter
flasher-symfony Symfony framework adapter
flasher-toastr-laravel Toastr adapter for Laravel
flasher-toastr-symfony Toastr adapter for Symfony
flasher-noty-laravel Noty adapter for Laravel
flasher-noty-symfony Noty adapter for Symfony
flasher-notyf-laravel Notyf adapter for Laravel
flasher-notyf-symfony Notyf adapter for Symfony
flasher-sweetalert-laravel SweetAlert adapter for Laravel
flasher-sweetalert-symfony SweetAlert adapter for Symfony

Note: Each adapter has its own repository. For detailed installation and usage instructions, please refer to the Official Documentation.

Official Documentation

Comprehensive documentation for PHPFlasher is available at https://php-flasher.io. Here you will find detailed guides, API references, and advanced usage examples to help you get the most out of PHPFlasher.

Contributors and sponsors

Join our team of contributors and make a lasting impact on our project!

We are always looking for passionate individuals who want to contribute their skills and ideas. Whether you're a developer, designer, or simply have a great idea, we welcome your participation and collaboration.

Shining stars of our community:

Younes ENNAJI
Younes ENNAJI

💻 📖 🚧
Salma Mourad
Salma Mourad

💵
Nashwan Abdullah
Nashwan Abdullah

💵
Arvid de Jong
Arvid de Jong

💵
Ash Allen
Ash Allen

🎨
Tony Murray
Tony Murray

💻
Stéphane P
Stéphane P

📖
Lucas Maciel
Lucas Maciel

🎨
Ahmed Gamal
Ahmed Gamal

💻 📖
Brooke.
Brooke.

📖

Contact

PHPFlasher is being actively developed by yoeunes. You can reach out with questions, bug reports, or feature requests on any of the following:

License

PHPFlasher is open-sourced software licensed under the MIT license.

Made with ❤️ by Younes ENNAJI

About

The main repository for PHPFlasher, a PHP library that makes it easy to add customizable notification messages to your web applications. Supports Laravel, Symfony, and standalone use. This monorepository enables efficient collaboration and version control among developers.

Topics

Resources

License

Security policy

Stars

Watchers

Forks