Laravel 10 Toastr Notification Without any Package

Hello Artisan, today I'll show you how to use Toastr notification in our Laravel application without the use of any package. Most of the time what we do is use some packages of Laravel and use the CDN version of jquery library as well. But here we don't going to use any Laravel package. So, no more talk let's see how we can easily add toastr notification in our application.

Table of Contents

  1. Setup Controller
  2. Setup View
  3. Setup Route
  4. Output

Setup Controller

So at first, we'll create a controller by firing the below command.

 php artisan make:controller ToastrController

It'll create a controller under app/Http/Controllers, open the file, and put toastr() method in your controller. Look at the below source code.


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ToastrController extends Controller
    public function toastr(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application
        session()->flash('success', 'This is a success message!');
        session()->flash('info', 'This is an info message!');
        session()->flash('warning', 'This is a warning message!');
        session()->flash('error', 'This is an error message!');

        return view('toastr');

Setup View

Now we need to set up the blade file, so that we can show the result in a nice way.

<!DOCTYPE html>
    <title>How To Notification Message PopUp Using Toastr Js Plugin Laravel 10 Example -</title>
    <link rel="stylesheet" href="">
    <link rel="stylesheet" type="text/css"
    <script src=""></script>
    <script src=""></script>
<div class="container mt-5">
    <div class="row">
        <div class="col-md-6 mx-auto">
            <div class="card">
                <div class="card-header">
                <div class="card-body">
                    <h5>Welcome to the</h5>

    // success message popup notification
    toastr.success("{{ session()->get('success') }}");

    // info message popup notification
    @if(session()->has('info'))"{{ session()->get('info') }}");

    // warning message popup notification
    toastr.warning("{{ session()->get('warning') }}");

    // error message popup notification
    toastr.error("{{ session()->get('error') }}");


Setup Route

Put the below route in the web.php file.

Route::get('/toastr', [App\Http\Controllers\ToastrController::class, 'toastr'])->name('toastr');


Now it's time to check the output. Go to localhost:8000/toastr, and you'll find the below output.

That's it for today. I hope it'll be helpful in upcoming projects. You can also download this source code from GitHub. Thanks for reading. ๐Ÿ™‚