Wednesday, March 8, 2017

laravel toastr js notification shows on every page

In my controller :

    public function showFreelancers(Request $request)
    {
        $authUser = Auth::user();
        session()->put('success','Item created successfully.');
        return view('freelancer/index',compact('authUser'));
    }

I have only one session()->put('success','Item created successfully.'); in my entire controller.

My layout page have the below code just above from . And from below all js files.

<script>

  @if(Session::has('success'))
        toastr.success("");
  @endif

  @if(Session::has('info'))
        toastr.info("");
  @endif

  @if(Session::has('warning'))
        toastr.warning("");
  @endif

  @if(Session::has('error'))
        toastr.error("");
  @endif

</script>

When i hit Route::get('/','FreelancerController@showFreelancers')->name('FreelancerIndex'); i get the message which is okay ! But when i open another route i get the exact same notification.

What i am doing wrong here ?



via Gamer

Advertisement