Notification Message show using a toastr in Laravel 7

When you are working on the live project you have to display a notification message on your screen so the user can show the display output what should have to they do.

That’s why jQuery plugin represents one of the easiest and best plugins which helps to display the notifications message on our screen.

So let’s start our tutorials

Step 1: Create a function in helper file

So open your helper.php file and put the below code.

function notificationMsg($text, $message){
    \Session::flash($text, $message);

Step 2: Changes in your Controller.

Now open your UserController.php file and put the below code.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class UserController extends Controller{
	public function index(){
		$users = User::paginate(10);
		notificationMsg('success', "User View Load!");
		return view('users',compact('users'));

Step 3: Changes in the route file.

Open your web.php file and put the below code.

Route::get('/users', 'UserController@index')->name('users');

Step 4: Changes in blade file.

Open your user/index.blade.php file and put the below code.

	<div aria-live="polite" aria-atomic="true" style="position: relative;">
        <div class="toast" style="position: fixed; top: 10px; right: 10px; z-index: 9999" data-delay="3000">
            <div class="toast-body bg-secondary">
                <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                <i id="icon-arrow" class="fa fa-check"></i>
                {!! session('success') !!}
	<table class="table table-bordered">
	            @foreach($users as $user)
	                    <td>{{ $user->name }}</td>
	                        <button class="btn">Delete</button>
	                <td>There are no data.</td>
	{!! $users->links() !!}	
	<script src=""></script>
	       @if(Session::has('success') && !empty(session('success')))

So, Here is the tutorial is ready. now, open your tutorial and put the below URL:

About Dhaval Shah

My name is Dhaval Shah. I'm a Laravel developer. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress, and Bootstrap.
Follow me on Github / Linkedin

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!