Download the PHP package theorythree/laratoaster without Composer
On this page you can find all versions of the php package theorythree/laratoaster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download theorythree/laratoaster
More information about theorythree/laratoaster
Files in theorythree/laratoaster
Package laratoaster
Short Description An easy-to-use alert helper for your Laravel projects.
License MIT
Homepage https://github.com/TheoryThree/LaraToaster
Informations about the package laratoaster
LaraToaster
Description
An easy-to-use notification utility for your Laravel projects.
How it Works
LaraToaster uses the Laravel Session class to create a Flash message from your controllers. When a message is detected, it will inject a Buefy Toast object and alert the user of your message.
How to Install
This package requires that you have Vue, Bulma and Buefy installed in your Laravel project.
Step 1: Via Composer
Step 2: Define the service provider and alias in your Laravel project
This package takes advantage of the new auto-discovery feature found in Laravel 5.5+. If you're using that version of Laravel, then you may skip this step and move on to Step 3.
Add LaraToaster Service Provider to config/app.php
.
Define the LaraToaster Alias in config/app.php
.
Step 3. Publish the plugin config file and the Vue Component file
Publish the configuration file to override the package defaults and install the LaraToaster.vue component.
$ php artisan vendor:publish --tag=laratoaster
This command will generate a config file
config/laratoaster.php
and it will install the LaraToaster Vue componentresources/assets/js/components/LaraToaster.vue
.
Step 4. Install Buefy + Bulma
If you haven't already, install Buefy. Doing so will also install Bulma.
$ yarn add buefy
Step 5. Register Vue Component
Register the LaraToaster Vue Component in resources/assets/js/app.js
.
Step 6. Run your compiler
Don't forget to run your compiler script to update your js files.
$ yarn run dev
or $ yarn run watch
Usage
LaraToaster can be used in your project whenever you need to notify the user of an event. Most commonly, in your CRUD controllers. LaraToaster uses the Session::flash
method to set a Flash message.
- Install package
- Include
Vue.component('laratoaster', require('./components/LaraToaster.vue'));
inresources/assets/js/app.js
- Include
{!! Toaster::toast() !!}
in your Blade template - Set the Toaster message in your controller (see example below)
make()
String make( String $type, String $message )
Description
This method can be used in your Blade template in cases when you wish to show an alert message every time the view is loaded. This method does not rely on a Session so it will trigger the alert instantly upon page load.
Important
The method returns a Vue component named
<laratoastert>
, so you must make sure that you use{!! !!}
instead of{{ }}
to bracket the method in your Blade template or the returned string will be escaped.Also, you must put the tag within an instantiated Vue element. In the examples we're using a div with an id of #app.
Parameters
$type
String: The type of message to be displayed. Accepts any class name supported by Buefy (do not include is-
in your type name). (Options: success
, warning
, danger
, black
,white
, dark
, light
, info
)
$message
String: The alert message to be displayed.
Example 1: Instant Toast
toast()
String toast()
Description
LaraToaster can also be used to rely on Session and this is more likely the setup you'll want to have in your projects. There are two parts to the setup. (1) the
toast()
method call in your Blade templates (which serves as a placeholder for where the<laratoaster>
element will be injected into your template) and (2) the use of one of the many method calls in your controllers.Below, we're using the
success()
method because we're optimists.
Important
The method returns a Vue component named
<laratoastert>
, so you must make sure that you use{!! !!}
instead of{{ }}
to bracket the method in your Blade template or the returned string will be escaped.Also, you must put the tag within an instantiated Vue element. In the examples we're using a div with an id of #app.
Example 2 - Standard Toaster Setup
success(), warning(), danger()
String [success, warning, danger]( String $message )
Description
These methods can be used in your controller files to set the type of alert message you wish to trigger. In all cases the a Session Flash message will be set with the message you provide.
Important
Do not forget to include
{!! Toaster::toast() !!}
in your Blade template within an instantiated Vue element.
Parameters
$message
String: The alert message to be displayed.
Example 3: Setting Your Toaster Messages
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
All contributors welcome. If you would like to contribute to this package please feel to submit a pull request, submit an issue, or request a feature.
See our CODE_OF_CONDUCT for more details.
Credits
- Dan Merfeld - Author and Maintainer.
Contact
Want to get in touch to discuss this package, or another one you'd like us to build? Feel free to reach out to the maintainer of this package by emailing me at @dmerfeld. I'd really like to hear from you. Honest.
License
The MIT License (MIT). Please see License File for more information.