项目作者: bkstar123

项目描述 :
A lightweight package to send flash messages in Laravel applications
高级语言: PHP
项目地址: git://github.com/bkstar123/flashing.git
创建时间: 2019-09-08T12:03:59Z
项目社区:https://github.com/bkstar123/flashing

开源协议:

下载


bkstar123/flashing

A lightweight package to send flash messages in Laravel applications. This package only supports one single flash message at a time, and the flash message is displayed in the format of a toast notification

1. Requirements

  • PHP 7.1.3+
  • Laravel 5.5+

2. Installation

  1. composer require bkstar123/flashing

After that, you need to publish the package’s assets:
php artisan vendor:publish --provider="Bkstar123\Flashing\FlashingServiceProvider"

It will copy a blade view element to your application’s resources/views/vendor/bkstar123_flashing/flashing.blade.php. You are free to customize this view element. Also, it will copy the package’s javascript files to your application’spublic/js/vendor/bkstar123)handling/*.js

3. Usage

a) In view

In view or master layout, just include the package’s view element with @include('bkstar123_flashing::flashing')

b) In controller methods

Out of the box, the package provides you with the following toolset for flashing a message:

  • Bkstar123\Flashing\Facades\Flashing Facade. Alternatively, you can use its alias Flashing
  • flashing() helper function

The package supports the following types of flashing messages:

  • success
  • error
  • warning
  • info (default)

Example:

  1. <?php
  2. // Flash a info-typed message by default
  3. \Flashing::message('Welcome to the home page')
  4. ->flash();
  5. flashing('Welcome to the home page')
  6. ->flash();
  7. // Flash a success-typed message
  8. \Flashing::message('Welcome to the home page')
  9. ->success()
  10. ->flash();
  11. flashing('Welcome to the home page')
  12. ->success()
  13. ->flash();
  14. // Flash a message and mark it as important i.e it will not disappear until being dismissed by yourself
  15. \Flashing::message('Important message')
  16. ->important()
  17. ->flash();
  18. flashing('Important message')
  19. ->important()
  20. ->flash();
  21. // Specify the miliseconds for timing out the flash message
  22. // The given timeout will be ignored if you mark the flash message as important
  23. \Flashing::message('This message will disappear after 3 seconds')
  24. ->timeout(3000)
  25. ->flash();
  26. flashing('This message will disappear after 3 seconds')
  27. ->timeout(3000)
  28. ->flash();
  29. // Specify the location of the flash message, it can be either top-right or bottom-right
  30. \Flashing::message('I will be on the top-right of your screen')
  31. ->position('top')
  32. ->flash();
  33. flashing('I will be on the top-right of your screen')
  34. ->position('top')
  35. ->flash();

All methods success() | error() | warning() | info() can be chained after message() as well as chained by important(), timeout() & position(). In the final, you must always append flash() to the chain.

Note: flashing('hello world') <=> \Flashing::message('hello world')