All Projects → coderello → Laraflash

coderello / Laraflash

Licence: mit
⚡ Flash messages on steroids.

Projects that are alternatives of or similar to Laraflash

Laravel Flash
A lightweight package to flash messages
Stars: ✭ 382 (+154.67%)
Mutual labels:  laravel, flash
koa-better-error-handler
A better error-handler for Lad and Koa. Makes `ctx.throw` awesome (best used with koa-404-handler)
Stars: ✭ 51 (-66%)
Mutual labels:  flash, messages
Technicsolder
PHP web app that brings incremental pack updates to the Technic Launcher and Technic Platform
Stars: ✭ 146 (-2.67%)
Mutual labels:  laravel
Laravel Translatable String Exporter
Translatable String Exporter for Laravel
Stars: ✭ 149 (-0.67%)
Mutual labels:  laravel
Discord
Discord notification channel for Laravel
Stars: ✭ 148 (-1.33%)
Mutual labels:  laravel
Laravel Disposable Email
Disposable email address validator for Laravel
Stars: ✭ 147 (-2%)
Mutual labels:  laravel
Laravel Shortcodes
Wordpress like shortcodes for Laravel 4.2, 5.x, 6.x, 7.x and 8.x
Stars: ✭ 148 (-1.33%)
Mutual labels:  laravel
Laravel Emoji
😄 This package assist you in getting started with emoji easily.
Stars: ✭ 146 (-2.67%)
Mutual labels:  laravel
Laravel Video
A laravel package to stream video content.
Stars: ✭ 150 (+0%)
Mutual labels:  laravel
Servermonitor
💓 Laravel package to periodically monitor the health of your server and application.
Stars: ✭ 148 (-1.33%)
Mutual labels:  laravel
Request Migrations
HTTP Request Migrations for API Versioning like Stripe
Stars: ✭ 149 (-0.67%)
Mutual labels:  laravel
Laravel Model Expires
A package to assign expiration dates to Eloquent models.
Stars: ✭ 148 (-1.33%)
Mutual labels:  laravel
Grosir Obat
Sebuah sistem kasir dan manajemen produk obat untuk penjualan Grosir
Stars: ✭ 147 (-2%)
Mutual labels:  laravel
Has Parameters
A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.
Stars: ✭ 149 (-0.67%)
Mutual labels:  laravel
Lms Laravel
Laravel Learning Management System (LMS)
Stars: ✭ 148 (-1.33%)
Mutual labels:  laravel
Laravel Admin Template
Laravel 4.2 Bootstrap Admin Starter Template [with Oracle DB Support]
Stars: ✭ 149 (-0.67%)
Mutual labels:  laravel
Speedy
🚄A Laravel Admin Package to create a website quickly
Stars: ✭ 146 (-2.67%)
Mutual labels:  laravel
Google Places Api
This is a PHP wrapper for Google Places API Web Service. And is Laravel Framework friendly.
Stars: ✭ 147 (-2%)
Mutual labels:  laravel
Apiserver
基于Laravel的API服务端架构代码
Stars: ✭ 148 (-1.33%)
Mutual labels:  laravel
Larapush
artisan push - Deploy your codebase into your web server with one Laravel artisan command and no SSH needed!
Stars: ✭ 150 (+0%)
Mutual labels:  laravel

Laraflash

Laraflash provides a handy way to work with the flash messages.

Latest Version Software License StyleCI Quality Score Coverage Status

Installation

You can install this package via composer using this command:

composer require coderello/laraflash 

After that you need to register the \Coderello\Laraflash\Middleware\HandleLaraflash::class middleware after the \Illuminate\Session\Middleware\StartSession::class one in the app\Http\Kernel.php

You can publish the config file with:

php artisan vendor:publish --tag="laraflash-config"

Adding flash messages

There are many syntax variations for adding flash messages, so you can choose the one you like the most.

Let's take a look at some of them.

use Coderello\Laraflash\Facades\Laraflash;

Laraflash::message()->content('Some content')->title('Some title')->type('success');

message() method creates and returns fresh FlashMessage instance which can be modified by chaining methods (all methods could be found in the FlashMessage methods section).

laraflash()->message()->content('Some content')->title('Some title')->type('success');

Laraflash facade can be replaced with the laraflsh() helper as you could saw in the example above.

laraflash()->message('Some content', 'Some title')->success();

message() method accepts up to five arguments: $content, $title, $type, $delay, $hops.

laraflash('Some content', 'Some title')->success();

Arguments mentioned in the previous example can be passed directly to the laraflash() helper.

Rendering flash messages

Ready flash messages could be rendered using the render() method of the Laraflash instance.

laraflash()->render();

All methods of the Laraflash instance (which could be obtained by calling laraflash() helper without arguments being passed) could be found in the Laraflash methods section.

Output HTML will be generated using skin, specified in the laraflash.skin config. All available skins are listed in the config file.

<div class="alert alert-danger" role="alert">
   Danger message.
</div><br><div class="alert alert-info" role="alert">
   Info message.
</div>

Default separator between the messages is the <br>, which is specified in the laraflash.separator config. Feel free to change it if you need.

Example of messages rendered as HTML:

Example

Obtaining flash messages as an array

Flash messages can be obtained as an array using the toArray() method.

laraflash()->toArray();

Here is the result:

[
  [
    "title" => null,
    "content" => "Instant message.",
    "type" => "danger",
    "hops" => 1,
    "delay" => 0,
  ],
]

You can use array representation of flash messages for your API.

Laraflash methods

message(?string $content = null, ?string $title = null, ?string $type = null, ?int $delay = null, ?int $hops = null): FlashMessage

Creates and returns fresh FlashMessage instance.

render()

Renders ready flash messages as HTML.

keep(): self

Adds one more hop to each flash message.

clear(): self

Deletes all flash messages.

all(): Collection

Returns the Collection instance containing all flash messages.

ready(): Collection

Returns the Collection instance containing ready flash messages.

touch(): self

Touches all flash messages (decrements amount of hops and delay, deletes expired messages).

toArray()

Returns an array representation of ready flash messages.

toJson()

Returns JSON representation of ready flash messages.

FlashMessage methods

content(?string $content): self

Sets the content of the flash message.

title(?string $title): self

Sets the title of the flash message.

type(?string $type): self

Sets the type of the flash message.

danger(): self

Sets the danger type for the flash message.

warning(): self

Sets the warning type for the flash message.

info(): self

Sets the info type for the flash message.

success(): self

Sets the success type for the flash message.

hops(int $hops): self

Sets the hops amount of the message (the number of requests in which the message will be present).

Default: 1

delay(int $delay): self

Sets the delay of the message (the number of requests in which the message will be waiting to receive the ready state).

Default: 1

now(): self

Shortcut for ->delay(0)

keep(): self

Increments the amount of hops.

attribute(string $key, $value = null): self

Sets the custom attribute which will be present in the array representation of the message and could be obtained using the get() method.

get(string $key)

Returns the value of the attribute.

toArray()

Returns an array representation of the message.

toJson()

Returns JSON representation of the message.

Testing

You can run the tests with:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

📖 License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].