Laravel 8 Toastr Notifications using yoeunes/toastr package

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
Laravel 8 Toastr Notifications using yoeunes/toastr package

Today now in this tutorial, i will show you how to install and use toastr notifications by using yoeunes/toastr package in laravel 8 applications. Now here we will use yoeunes/toastr package for toastr notifications. So here we will write code step by step tutorial for laravel 8 toastr notifications.

For Toastr notifications in yoeunes/toastr package provides us warning,success,error and info notifications. So we need to just follow few steps for implement toastr notifications in our laravel application. So now in this example i give you a short example from scratch. Now just need to follow bellow step.

Step 1: Install yoeunes/toastr package

Now we need to install yoeunes/toastr composer package for datatable, So we can install by using following command:

$ composer require yoeunes/toastr

After successfully do that we need to set providers and alias.

config/app.php

'providers' => [
    ...
    Yoeunes\Toastr\ToastrServiceProvider::class
    ...
];

So as optional if we want to modify the default configuration, we can publish the configuration file:

php artisan vendor:publish --provider='Yoeunes\Toastr\ToastrServiceProvider'
Step 2: Create Route

Now in this is step we need to create a route for datatables layout file and also another one for getting data. So open your routes/web.php file and add following route.

routes/web.php

Route::get('home', 'HomeController@index')->name('home');
Step 5: Create Controller

So now in this point, we should create a new controller as HomeController. On this controller will manage layout and getting data request and return response. So just put bellow content in controller file:

app/Http/Controllers/HomeController.php

Success Toastr Notifications For Controller Code
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function index()
    {
        toastr()->success('Success Message');
        return view('home');
    }
}
Error Toastr Notifications For Controller Code
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function index()
    {
        toastr()->error('Error Message');
        return view('home');
    }
}
Info Toastr Notifications For Controller Code
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function index()
    {
        toastr()->info('Info Message');
        return view('home');
    }
}
Warning Toastr Notifications For Controller Code
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function index()
    {
        toastr()->warning('Warning Message');
        return view('home');
    }
}
Step 3: Create View

Now we are in our Last step, so now let’s create users.blade.php(resources/views/home.blade.php) for layout and then we will write design code here and put following code:

resources/views/home.blade.php

<!DOCTYPE html>
<html>
<head>
   <title>Laravel 6 Toastr Notifications using yoeunes/toastr package - codingspoint.com </title>
   <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css">
   @toastr_css
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-6 offset-md-3 mt-5">
            <div class="card">
                <div class="card-header text-center ">
                    Laravel 6 Toastr Notifications using yoeunes/toastr package  - Codingspoint.com
                </div>
                <div class="card-body text-center p-5">
                    Check For Toastr Notification
                </div>
            </div>
        </div>
    </div>
</div>
</body>
@jquery
@toastr_js
@toastr_render
</html>

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us onĀ Facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →