Giter VIP home page Giter VIP logo

toastr's Introduction

Toastr.js notifications for Laravel

๐Ÿ‘€ This package helps you to add toastr.js notifications to your Laravel projects.

Latest Stable Version Latest Unstable Version Total Downloads License

toastr

Version 3 Update

With the release of version 3, yoeunes/toastr is now powered by PHPFlasher. When you install this package, it automatically utilizes PHPFlasher under the hood. For those who are already using PHPFlasher or are interested in a more direct implementation, you might consider using PHPFlasher directly as it offers the same API and additional features.

Install

You can install the package using composer

composer require yoeunes/toastr

After installation, publish the assets using:

php artisan flasher:install

Usage:

The usage of this package is very simple and straightforward. it only required one step to use it :

Use toastr() helper function inside your controller to set a toast notification for info, success, warning or error

// Display a success toast with no title
flash()->success('Operation completed successfully.');

As an example:

<?php

namespace App\Http\Controllers;

use App\Post;
use App\Http\Requests\PostRequest;
use Illuminate\Database\Eloquent\Model;

class PostController extends Controller
{
    public function store(PostRequest $request)
    {
        $post = Post::create($request->only(['title', 'body']));

        if ($post instanceof Model) {
            toastr()->success('Data has been saved successfully!');

            return redirect()->route('posts.index');
        }

        toastr()->error('An error has occurred please try again later.');

        return back();
    }
}

License

MIT

toastr's People

Contributors

khatriafaz avatar lloricode avatar ookapratama avatar stylecibot avatar whereislucas avatar yoeunes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toastr's Issues

Not popping up when used in methods

When using in a method like Store or Update, the toast never pops up

When used in the index method it does pop up... So it's setup correctly, it's just not working after a redirect

Jquery conflict being duplicated on the page with the toast

Describe the bug
The bug consists of duplicating the page's jQuery if it already has an imported jQuery script, after toastr's popup returns.

To Reproduce
Steps to reproduce the behavior:

  1. Import cdn from jQuery in a page
  2. Have a jquery code on that page. in my example I had jQuery to control the opening and closing of a modal.
  3. Create a route to leave this page and return to it by displaying the popup in my example I had a modal to confirm the deletion of a user where it returned to that same page after being deleted.
  4. In the inspect element you will see that the jquery is again imported via cdn by a file called flasher.min.js. Thus preventing the modal from being controlled by jquery again because it is duplicated.

Expected behavior
It is expected that jQuery will stop working due to duplicate imports.

Desktop (please complete the following information):

  • OS: iOS 10.15.7 Catalina
  • Browser Firefox
  • Laravel 9

Additional context

  • toastr v2.3.0

The default CSS class 'toast' gets overlapped by Bootstrap

  • Toastr Version: 1.2.3
  • Laravel Version: 7
  • PHP Version: 7.3

Description:

The default CSS class 'toast', used by default, gets overridden for the same class used by Bootstrap. So, Bootstrap adds extra styles that breaks Toastr boxes.

I was able to solve it adding a config/toastr.php file and using another class, like: 'toastClass' => 'toastr'

Steps To Reproduce:

Just installing Bootstrap and Toastr, and firing any msg

not working with Laravel 7.

  • Toastr Version: #.#.#
  • Laravel Version: 7
  • PHP Version: 7.3.*

Description:

Toastr Is unable to install in laravel 7

Steps To Reproduce:

Kindly test it make installabale

How to translate the messages

Hi, i'd like to know how to translate the Success word from the toastr mensage.

image

I'm from Brazil and i need to translate it to portugueses.

Thanks!!!

Error Class 'Yoeunes\Toastr\ToastrServiceProvider' not found

  • Toastr Version: Latest
  • Laravel Version: 8.0
  • PHP Version: 7.2

Description:

Class 'Yoeunes\Toastr\ToastrServiceProvider' not found

Steps To Reproduce:

Yoeunes\Toastr installed by composer in local and migrated by ftp to new server

Class added to providers

Add blade directives in boot method

I can't get render blade directives in many causes. In docs i can see: Blade directive need to be registered in boot method. I can resolve my trouble whit this.

Using toastr with ajax

  • Toastr Version: 1.2.3
  • Laravel Version: 7.1.3
  • PHP Version: 7.4.3

Description:

Hi, there is any way to render the toastr without refresh or redirect the user? This would be nice for using with ajax requests.

Steps To Reproduce:

Config file not publishing

First, THANK YOU for the hard work of making this happen. It makes it much easier than having to reinvent the wheel when it comes to my projects. ๐Ÿฅ‡

When I used the method of publishing the config file that you specified in the readme, it does not publish to the config directory in Laravel.

As optional if you want to modify the default configuration, you can publish the configuration file:
$ php artisan vendor:publish --provider='Yoeunes\Toastr\ToastrServiceProvider' --tag="config"

I worked around the issue by modifying the config file that is in the src package, but I do not like doing that.

Thanks again!

Limit the number of displayed toasts or option to clear the toasts

Hello!
At first place, I want to thank you for this project! It's great.

I have an issue using it in my app, because I need the option to set the maximum number of displayed toasts to 1, or option to clear previous toasts before the last toastr('') in the controller.

Are there such options available?

Thank you in advance!

Hello there is problem in jsdeliver cdn in egypt https://cdn.jsdelivr.net/npm/@flasher/[email protected]/dist/flasher.min.js is blocked in egypt what is the replacement ?

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. Windows 10, iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Severity

  • High
  • Medium
  • Low

Related Issues

  • #

Additional context

  • Provide version of the yoeunes/toastr.
  • Provide the error log or any other relevant debugging information.
  • Add any other context about the problem here.

vscode undefined function toastr()

Describe the bug
vscode display error
Undefined Function 'App\Http\Controllers\toastr'

but it works in browser. (just showing unnecessary error in vscode)

i don't know if this is bug or not. but maybe any suggestion to get rid off this error?

To Reproduce
Steps to reproduce the behavior:

  1. install toastr via composer
  2. use toastr() function in any controllers

Expected behavior
there is no error in vscode terminal

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Firefox
  • VS Code 1.74.3
  • Laravel 9

Additional context

  • toastr v2.3

toastr destory or clear not working?

Describe the bug
Toastris opens again when I return to the same URL in Laravel
How can I destroy or clear it once it's done?
To Reproduce

Desktop (please complete the following information):

  • OS: [e.g. Windows 10, iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Severity

  • High
  • Medium
  • Low

Error Installing/Update toastr in Laravel 11

I am using Laravel 11 and I'm currently faced this issue when Installing toastr.

Here's the Error. Could fix the error as soon as Possible.

Symfony\Component\ErrorHandler\Error\FatalError

Declaration of Flasher\Laravel\Command\InstallCommand::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) must be compatible with Symfony\Component\Console\Command\Command::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output): int

at vendor\php-flasher\flasher-laravel\Command\InstallCommand.php:35
PHP Fatal error: Declaration of Flasher\Laravel\Command\InstallCommand::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) must be compatible with Symfony\Component\Console\Command\Command::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output): int in C:\Users\Makuguren\Documents\CAPSTONE PROJECT\PiLock-Admin-Laravel-10-2\vendor\php-flasher\flasher-laravel\Command\InstallCommand.php on line 35
31โ–•
32โ–• /**
33โ–• * @return int
34โ–• */
โžœ 35โ–• protected function execute(InputInterface $input, OutputInterface $output)
36โ–• {
37โ–• $output->writeln('');
38โ–• $output->writeln('
39โ–• โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—

Whoops\Exception\ErrorException

Declaration of Flasher\Laravel\Command\InstallCommand::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) must be compatible with Symfony\Component\Console\Command\Command::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output): int

at vendor\php-flasher\flasher-laravel\Command\InstallCommand.php:35
31โ–•
32โ–• /**
33โ–• * @return int
34โ–• */
โžœ 35โ–• protected function execute(InputInterface $input, OutputInterface $output)
36โ–• {
37โ–• $output->writeln('');
38โ–• $output->writeln('
39โ–• โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—

1 vendor\filp\whoops\src\Whoops\Run.php:510
Whoops\Run::handleError("Declaration of Flasher\Laravel\Command\InstallCommand::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output) must be compatible with Symfony\Component\Console\Command\Command::execute(Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output): int", "C:\Users\Makuguren\Documents\CAPSTONE PROJECT\PiLock-Admin-Laravel-10-2\vendor\php-flasher\flasher-laravel\Command\InstallCommand.php")

2 [internal]:0
Whoops\Run::handleShutdown()

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

toastr.php doesn't show up.

php artisan vendor:publish --provider='Yoeunes\Toastr\ToastrServiceProvider' --tag="config"

This command doesn't work for laravel 5.6.

toastr shows up again when trying to go back

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?

The Toast only is showed on next refresh

Describe the bug
The Toast only is showed on next refresh

To Reproduce
Steps to reproduce the behavior:

  1. composer install yoeunes/toastr
  2. php artisan make:livewire test
  3. public function onTest()
    {
    toastr()->success(__('test!'));
    }
  4. {{ __('Test toaster') }}
  5. Nothing happens but if I reload the page in browser, the toast appears

Expected behavior
The toast should show on click button

Desktop (please complete the following information):

  • OS: Linux, Apache 2.4, php 8.2
  • Browser chrome
  • Laravel: 10.26 with livewire and jetstream

Severity

  • [*] Low

Additional context

  • Provide version of the yoeunes/toastr.
  • Provide the error log or any other relevant debugging information.
  • Add any other context about the problem here.

Unable to locate publishable resources

  • Toastr Version: 1.2.2
  • Laravel Version: 6.15.1
  • PHP Version: 7.3.9

Description:

As described in #13, publishing the config file currently fails with the error message "Unable to locate publishable resources".

Steps To Reproduce:

Try to publish the config file

image

The response is not a view.

Describe the bug
In our application, we often assert if the correct view is returned like so:

$response = $this->get(route('index'));

$response->assertOk()
    ->assertViewIs('dashboard.index');

This works with Laravel 9 and your yoeunes/toastr v1, but since upgrading to Laravel 10 and yoeunes/toastr v2 all tests that use assertViewIs now return the following error: The response is not a view.

I think this may be caused by adding the CDN link to flasher in every view.

Sidenote The pages that "don't return a view" do still work as intended.

To Reproduce
Steps to reproduce the behaviour:

  1. Make a blank Laravel project (composer create-project laravel/laravel 'project-name')
  2. Change tests/Feature/Exampletext: replace ->assertStatus(200) with ->assertOk()->assertViewIs('welcome').
  3. Run the test, see that this works.
  4. Add yoeunes/toastr v2 to the project (composer require yoeunes/toastr)
  5. Run the test again, see that it fails.

Expected behavior
What should otherwise be valid views in Laravel, should not suddenly become invalid, or no views.

Screenshots
image

Desktop (please complete the following information):

  • OS: The application runs in a Debian Linux pod (FROM php:8-apache). This problem also occurs when running it in macOS 14.2.1 (23C71)
  • Testsuite: PHPUnit 10
  • Version: yoeunes/toastr is version 2.3

Severity

  • High (as we need this to work and we need to upgrade to Laravel 10 which does not work with yoeunes/toastr v2)
  • Medium
  • Low

jQuery Clashes

Describe the bug
A clear and concise description of what the bug is.
package's jquery cdn often clashes with preloaded project's jquery and causes other libraries to malfunction.
To Reproduce
Steps to reproduce the behavior:

  1. Add a jquery cdn in your laravel project's base file.
  2. Use any other library which manipulates the DOM
  3. Execute toastr()
  4. Check console for the error of other library not found or "something is not a function"

Expected behavior
A clear and concise description of what you expected to happen.
It should run smoothly as it was without the toast
Screenshots
If applicable, add screenshots to help explain your problem.
image
Error occur with the toastr
image

image
After commenting this cdn it is working as it should.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.