PHPackages                             theorythree/laratoaster - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. theorythree/laratoaster

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

theorythree/laratoaster
=======================

An easy-to-use alert helper for your Laravel projects.

v1.0.1(8y ago)2276MITPHPPHP ~5.6|~7.0

Since Jan 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/theorythree/LaraToaster)[ Packagist](https://packagist.org/packages/theorythree/laratoaster)[ Docs](https://github.com/TheoryThree/LaraToaster)[ RSS](/packages/theorythree-laratoaster/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

LaraToaster
===========

[](#laratoaster)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8068fe7f41c4627530d6c2e9b408c7d0ac828dd8d5ac62b48e3cec1743e517c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7468656f727974687265652f4c617261546f61737465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/theorythree/LaraToaster)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/71ada29c54671e700c2b087847bddccf1f340919d2c60fe1a001c22476bd2e43/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468656f727974687265652f4c617261546f6173742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/theorythree/LaraToaster)[![Total Downloads](https://camo.githubusercontent.com/4e8c419212b13924bdbe80492cb3d8783786a4b240de452e0837a1bcdef7648a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7468656f727974687265652f4c617261546f61737465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/theorythree/LaraToaster)

Description
-----------

[](#description)

> An easy-to-use notification utility for your Laravel projects.

How it Works
------------

[](#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
--------------

[](#how-to-install)

> This package requires that you have [Vue](https://vuejs.org), [Bulma](https://bulma.io) and [Buefy](https://buefy.github.io) installed in your Laravel project.

### Step 1: Via Composer

[](#step-1-via-composer)

```
$ composer require theorythree/laratoaster
```

### Step 2: Define the service provider and alias in your Laravel project

[](#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`.

```
'providers' => [

  /*
   * Application Service Providers...
   */

  TheoryThree\LaraToaster\LaraToasterServiceProvider::class,
];
```

Define the LaraToaster Alias in `config/app.php`.

```
'aliases' => [

  /*
   * Aliases
   */
  'Toaster' => TheoryThree\LaraToaster\LaraToasterFacade::class,
];
```

### Step 3. Publish the plugin config file and the Vue Component file

[](#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 component `resources/assets/js/components/LaraToaster.vue`.

### Step 4. Install Buefy + Bulma

[](#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

[](#step-5-register-vue-component)

Register the LaraToaster Vue Component in `resources/assets/js/app.js`.

```
// import BUEFY
import Buefy from 'buefy'
// Use Buefy
Vue.use(Buefy)

// Register LaraToast Vue Component
Vue.component('laratoaster', require('./components/LaraToaster.vue').default);

// Make sure to have a New Vue instance setup
const app = new Vue({
    el: '#app'
});
```

### Step 6. Run your compiler

[](#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

[](#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.

1. Install package
2. Include `Vue.component('laratoaster', require('./components/LaraToaster.vue'));` in `resources/assets/js/app.js`
3. Include `{!! Toaster::toast() !!}` in your Blade template
4. Set the Toaster message in your controller (see example below)

---

### make()

[](#make)

`String make( String $type, String $message )`

#### Description

[](#description-1)

> 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 ``, 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

[](#parameters)

###### $type

[](#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

[](#message)

String: The alert message to be displayed.

#### Example 1: Instant Toast

[](#example-1-instant-toast)

```
// resources/js/app.js
// make sure the Vue component is registered
Vue.component('laratoaster', require('./components/LaraToaster.vue'));

// make sure the Vue is set to the HTML element contained in your Blade template
// In this example, we're assuming a div with an id of #app.
const app = new Vue({
    el: '#app'
});
```

```

  {!! Toaster::make("success","Instant toast, made right in the template!") !!}

```

---

### toast()

[](#toast)

`String toast()`

#### Description

[](#description-2)

> 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 `` 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 ``, 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

[](#example-2---standard-toaster-setup)

```
// resources/js/app.js
// make sure the Vue component is registered
Vue.component('laratoaster', require('./components/LaraToaster.vue'));

// make sure the Vue is set to the HTML element contained in your Blade template
// In this example, we're assuming a div with an id of #app.
const app = new Vue({
    el: '#app'
});
```

```

  {!! Toaster::toast() !!}

```

```
