hajtuj/laravel-flash-messages

Simple, session based flash messages for Laravel application.

1.2.1 2021-04-27 07:37 UTC

This package is auto-updated.

Last update: 2024-08-27 15:01:00 UTC


README

Simple, session based flash messages for Laravel applications.

Latest Version on Packagist License StyleCI

Alerts

Content

Installation

Just pull package through composer

composer require hajtuj/laravel-flash-messages

Add component tag to Your layout template

<x-flash-message-bootstrap/>

Package is created to work as default with css framework Twitter Bootstrap v4. Information how to add boostrap to Your project or simply add inline link to css file of bootstrap:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" crossorigin="anonymous">

and js file to make messages able to hide:

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" crossorigin="anonymous"></script>

Usage

U can simply call flash messages from macro added to RedirectResponse. Macro name is created from config macro values and type of flash message:

macro prefix + type + macro suffix

public function store() {
    return redirect('/')->successMsg('Your message');
}
public function store() {
    return back()->successMsg('Your message');
}

You are able to use handy helper method:

public function store() {
    flash('message', 'info');
    return back();
}

or by chaining it with message type:

public function store() {
    flash('message')->success();
    return back();
}

You can also receive class of FlashMessageContract $flash in constructor method of your controller:

public function store(FlashMessageContract $flash) {
    $flash->flashMessage('Hey! Successfully stored resource', 'success');
}

Setup

You can always export config file and views to make your own modifications

exporting config to config/flash-message.php

$ php artisan flash-message:config

exporting view file to resources/views/vendor/flash-message/bootstrap.blade.php

$ php artisan flash-message:views

you can add own types of messages in to config file:

/**
 *  Types are used to name classes in html code of alerts
 */
'types' => ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'],

to modify class for each type add own suffix and prefixes in config file

/**
* Class prefix and suffix is added to type of alert to create class name
*/
'class' => [
    'prefix' => 'alert-',
    'suffix' => '',
],

Donations

If You like my work and U would like to share with me just
Buy Me A Coffee

License

License