yoeunes / toastr

:eyes: toastr.js notifications for Laravel
https://php-flasher.io
MIT License
375 stars 52 forks source link

toastr shows up again when trying to go back #36

Open 2jiwon opened 1 year ago

2jiwon commented 1 year ago

Hello, I am using toastr and it's a great package.

Actually, I have a question. toastr message shows up again when I try to go back on view page.

Here's some part of my code. // controller

toastr()->success('complete. \\n'.$return, '', ['timeOut' => 5000, 'positionClass' => 'toast-center-center']);
return redirect()->back();

// blade

@if (Session::has('success'))
         <div class="row justify-content-end">
               <div class="col-3 col-align-self-end alert alert-success alert-block">
                   <button type="button" class="close" data-dismiss="alert">×</button>
                       <strong>
                          toastr.success("{{ $message }}");
                        </strong>
                 </div>
          </div>
@endif

....

<!-- container-fluid end -->

@toastr_css
@toastr_js
@toastr_render

Did I do something wrong here? Or could you tell me where should I check for?

yoeunes commented 1 year ago

Hello @2jiwon, thank you for using the yoeunes/toastr package. I noticed that you are currently using an outdated version of the package. To resolve any potential issues, I would recommend upgrading to the latest version by running the following command: composer require yoeunes/toastr::^2.3.

Additionally, I suggest removing all the code related to the outdated version from your blade template. This should help ensure that the latest version works seamlessly with your project. Thank you again for using this package, and please let me know if you have any questions or concerns.

2jiwon commented 1 year ago

@yoeunes Thank you for your reply. I tried what you suggested composer require yoeunes/toastr::^2.3 then it says

 [UnexpectedValueException]                                                
  Could not parse version constraint :^2.3: Invalid version string ":^2.3"

so I also tried composer require yoeunes/toastr^2.3 just in case, but it didn't work either.

2jiwon commented 1 year ago

@yoeunes oops, nevermind. it was because my composer version. I was able to update to 2.3. However, the situation that showing up twice is still exists.

yoeunes commented 1 year ago

please remove all this code from your blade template:

@if (Session::has('success'))
         <div class="row justify-content-end">
               <div class="col-3 col-align-self-end alert alert-success alert-block">
                   <button type="button" class="close" data-dismiss="alert">×</button>
                       <strong>
                          toastr.success("{{ $message }}");
                        </strong>
                 </div>
          </div>
@endif

....

<!-- container-fluid end -->

@toastr_css
@toastr_js
@toastr_render
madfortech commented 11 months ago

when i add this layout app.blade.php @toastr_css @toastr_js @toastr_render Capture1

PHP 8.1.17 (cli) (built: Mar 14 2023 23:07:43) (ZTS Visual C++ 2019 x64) Copyright (c) The PHP Group Zend Engine v4.1.17, Copyright (c) Zend Technologies

laravel . 10.18.0 version

Here my PostController Code $post = Post::create([ 'title' => $request->input('title'), 'description' => $request->input('description'), 'slug' => Str::slug($request->input('title')), // Generate slug ]);

    if ($request->hasFile('avatar')) {
        $post->addMedia($request->file('avatar'))
            ->toMediaCollection('avatars'); // You can customize the collection name as needed
    }

    toastr()::success('Post created successfully!', 'Success'); // Display a success toast message
    //
          Undefined function 'App\Http\Controllers\toastr'
    //
    any one help me fix htis