Skip to content

Commit

Permalink
Minor Changes in Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
realrashid committed Jun 11, 2020
1 parent 94f0fc4 commit 51e2994
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ All available types `toast_error` `toast_success` `toast_info` `toast_warning` `
!> You can not use helper methods with Middleware but you can set default values in `config/sweetalert.php` file! **Recommend** to use the .env keys.

```
SWEET_ALERT_MIDDLEWARE_AUTO_CLOSE=false
SWEET_ALERT_MIDDLEWARE_TOAST_POSITION='top-end'
SWEET_ALERT_MIDDLEWARE_TOAST_CLOSE_BUTTON=true
SWEET_ALERT_MIDDLEWARE_ALERT_AUTO_CLOSE=5000
SWEET_ALERT_MIDDLEWARE_ALERT_CLOSE_TIME=5000
SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES=true
```

> Positions **'top'**, **'top-start'**, **'top-end'**,
Expand Down
9 changes: 7 additions & 2 deletions src/Toaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ protected function setDefaultConfig()
*/
public function middleware()
{
unset($this->config['position'], $this->config['heightAuto'], $this->config['width'], $this->config['padding'], $this->config['showCloseButton'], $this->config['timer']);
unset($this->config['position'], $this->config['heightAuto'], $this->config['width'], $this->config['padding'], $this->config['showCloseButton']);

if(!config('sweetalert.middleware.autoClose')){
$this->removeTimer();
}else{
unset($this->config['timer']);
$this->config['timer'] = config('sweetalert.middleware.timer');
}
$this->config['position'] = config('sweetalert.middleware.toast_position');
$this->config['showCloseButton'] = config('sweetalert.middleware.toast_close_button');
$this->config['timer'] = config('sweetalert.middleware.alert_auto_close');

$this->flash();

Expand Down
4 changes: 3 additions & 1 deletion src/config/sweetalert.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@

'middleware' => [

'autoClose' => env('SWEET_ALERT_MIDDLEWARE_AUTO_CLOSE', false),

'toast_position' => env('SWEET_ALERT_MIDDLEWARE_TOAST_POSITION', 'top-end'),

'toast_close_button' => env('SWEET_ALERT_MIDDLEWARE_TOAST_CLOSE_BUTTON', true),

'alert_auto_close' => env('SWEET_ALERT_MIDDLEWARE_ALERT_AUTO_CLOSE', 5000),
'timer' => env('SWEET_ALERT_MIDDLEWARE_ALERT_CLOSE_TIME', 6000),

'auto_display_error_messages' => env('SWEET_ALERT_AUTO_DISPLAY_ERROR_MESSAGES', false),
],
Expand Down

0 comments on commit 51e2994

Please sign in to comment.