Skip to content

Toastr Notifications Not Displaying in Laravel 11.9 Controller #51

@RehamTammam1

Description

@RehamTammam1

Hello, I'm using Laravel 11.9 and following the instructions to integrate Toastr notifications with the Flasher package in my application. However, the notifications are not displaying as expected.
Problem:
After saving a new grade, I expect a Toastr notification to appear confirming that the data was saved successfully. However, no notifications are displayed.
Expected Behavior:
A Toastr notification should display a success message when the grade is successfully saved.

<?php 
namespace App\Http\Controllers\Grades;

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreGradeRequest;
use App\Models\Grade as ModelsGrade;
use Flasher\Toastr\Prime\ToastrInterface;
use Illuminate\Http\Request;
use Flasher\Notyf\Prime\NotyfInterface;
use Flasher\Toastr\Prime\Toastr;

use function Flasher\Toastr\Prime\toastr;

class GradeController extends Controller 
{
  public function index()
  {
    $grades = ModelsGrade::all();
    return view('grades.gradelist', compact('grades'));
  }

  public function store(StoreGradeRequest $request)
  {
    $validated = $request->validated();

    $grade = new ModelsGrade();
    $grade->Name = ['en' => $request->Name_en, 'ar' => $request->Name];
    $grade->Notes = $request->Notes;
    $grade->save();

    if ($grade instanceof ModelsGrade) {
      flash()->success('Operation completed successfully.');
      toastr()->success('Data has been saved successfully!');
      return redirect()->route('grades.index');
    }
  }
  
  // Other methods omitted for brevity
}
?>

Actual Behavior:
No notifications are displayed, even though the session data contains the notification information.

Additional Information:

Laravel Version: 11.9
PHP Version: 8.2
Flasher Package: php-flasher/flasher-toastr
Could you please assist in identifying why the Toastr notifications aren't displaying?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions