https://github.com/mujhtech/laravel-navtoastr
NavToastr Notifications and Custom Redirection for Laravel App
https://github.com/mujhtech/laravel-navtoastr
flash laravel navtoastr notification php redirection toastr
Last synced: about 1 month ago
JSON representation
NavToastr Notifications and Custom Redirection for Laravel App
- Host: GitHub
- URL: https://github.com/mujhtech/laravel-navtoastr
- Owner: Mujhtech
- License: mit
- Created: 2021-06-23T09:40:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-25T09:45:52.000Z (almost 5 years ago)
- Last Synced: 2025-02-26T05:45:40.674Z (over 1 year ago)
- Topics: flash, laravel, navtoastr, notification, php, redirection, toastr
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
NavToastr Notifications and Custom Redirection for Laravel App
>

:eyes: This package helps you to add Toast.js notifications to your Laravel app
## Install
You can install the package using composer
```sh
$ composer require mujhtech/nav-toastr
```
Then add the service provider to `config/app.php`. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.
```php
'providers' => [
...
Mujhtech\NavToastr\NavToastrServiceProvider::class
...
];
```
To install the configuration and assets file run:
```sh
$ php artisan navtoastr:install"
```
## Usage:
Include [app.css] and [app.js](https://github.com/ireade/Toast.js) in your view template:
1. Link to app.css `` or `@navtoastrCss`
2. Link to app.js `` or `@navtoastrJs`
4. use `navtoastr()` helper function inside your controller to set a toast notification for info, success, warning or error
```php
// Display an info toast with no title
navtoastr()->info('Are you the 6 fingered man?')
```
as an example:
```php
only(['username', 'password']));
if ($post instanceof Model) {
navtoastr()->success('Data has been saved successfully!');
return navtoastr()->named('posts.index');
}
navtoastr()->error('An error has occurred please try again later.');
return navtoastr()->back();
}
}
```
After that add the `@navtoastrRender` at the bottom of your view to actualy render the nav-toastr notifications.
```blade
Nav Toastr.js
@navtoastrCss
@navtoastrJs
@navtoastrRender
```
### Other Options
```php
// Set a info toast
navtoastr()->info('My name is Muhideen Mujeeb')
// Set a success toast
navtoastr()->success('Have fun storming the castle!')
// Set an error toast
navtoastr()->error('I do not think that word means what you think it means.')
// Set an warning toast
navtoastr()->warning('We do have the Kapua suite available.')
```
### Other api methods:
// You can also chain multiple messages together using method chaining
```php
navtoastr()->info('Are you the 6 fingered man?')->success('Have fun storming the castle!')->warning('doritos');
```
// you could replace `@navtoastrRender` by :
```php
navtoastr()->render() or app('nav-toastr')->render()
```
// you can use `navtoastr('')` instead of `navtoastr()->success()`
```php
function toastr(string $message = null, string $type = 'success', string $title = '', bool $enableCustomButton = false);
```
so
* `navtoastr($message)` is equivalent to `navtoastr()->success($message)`
* `navtoastr($message, 'info', true)` is equivalent to `navtoastr()->info($message, true)`
* `navtoastr($message, 'warning', true)` is equivalent to `navtoastr()->warning($message, true)`
* `navtoastr($message, 'error', false) ` is equivalent to `navtoastr()->error($message, false)`
### configuration:
```php
// config/nav-toastr.php
[
[
'text' => 'Refresh the page',
'reload' => true
],
[
'text' => 'My Website',
'url' => 'https://mujh.tech'
],
[
'text' => 'Twitter',
'url' => 'https://twitter.com/mujhtech'
]
],
];
```
## Credits
- [Mujhtech](https://github.com/mujhtech)
- [Ire Aderinokun](https://github.com/ireade)
## License
MIT


