├── .gitignore ├── src ├── helper.php ├── ReminderFacade.php ├── config │ └── config.php ├── ReminderServiceProvider.php └── Reminder.php ├── composer.json ├── license └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /src/helper.php: -------------------------------------------------------------------------------- 1 | [ 5 | "closeButton" => false, 6 | "debug" => false, 7 | "newestOnTop" => false, 8 | "progressBar" => false, 9 | "positionClass" => "toast-top-right", 10 | "preventDuplicates" => false, 11 | "onclick" => null, 12 | "showDuration" => "300", 13 | "hideDuration" => "1000", 14 | "timeOut" => "5000", 15 | "extendedTimeOut" => "1000", 16 | "showEasing" => "swing", 17 | "hideEasing" => "linear", 18 | "showMethod" => "fadeIn", 19 | "hideMethod" => "fadeOut" 20 | ], 21 | ]; 22 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 RryLee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/ReminderServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 24 | __DIR__ . '/config/config.php' => config_path('reminder.php'), 25 | ], 'config'); 26 | } 27 | 28 | /** 29 | * Register the service provider. 30 | * 31 | * @return void 32 | */ 33 | public function register() 34 | { 35 | $this->app->bindShared('reminder', function ($app) 36 | { 37 | return new Reminder($app->session, $app->config); 38 | }); 39 | } 40 | 41 | /** 42 | * Get the services provider by the provider 43 | * 44 | * @return array 45 | */ 46 | public function provides() 47 | { 48 | return ['reminder']; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # laravel-reminder 2 | 3 | Inspired by [laracasts flash](https://github.com/laracasts/flash) 4 | 5 | ### install 6 | 7 | Using Composer 8 | 9 | composer require rry/reminder 10 | 11 | Add the service provider to `config/app.php` 12 | 13 | ```php 14 | Rry\Reminder\ReminderServiceProvider::class, 15 | ``` 16 | 17 | Optionally include the Facade in config/app.php if you'd like. 18 | 19 | ```php 20 | 'Reminder' => Rry\Reminder\ReminderFacade::class, 21 | ``` 22 | 23 | > You can use reminder() function available. 24 | 25 | ### Dependencies 26 | 27 | jQuery [toast](https://github.com/CodeSeven/toastr), you need to add css and js to your html. 28 | 29 | ### Basic 30 | 31 | You should add `{!! Reminder::message() !!}` to your html. 32 | 33 | Then. 34 | 35 | * Reminder::info('foo', 'bar', []); 36 | 37 | * Reminder::success('foo', 'bar', []); 38 | 39 | * Reminder::warning('foo', 'bar', []); 40 | 41 | * Reminder::error('foo', 'bar', []); 42 | 43 | * reminder()->info('foo', 'bar', []); 44 | 45 | ```php 46 | "toast-bottom-right"]); 50 | 51 | return view('welcome'); 52 | }); 53 | ``` 54 | 55 | ```html 56 | 57 | 58 | 59 | Laravel 60 | 61 | 62 | 63 |
64 |
65 |
Laravel 5
66 |
67 |
68 | 69 | 70 | 71 | {!! reminder()->message() !!} 72 | 73 | 74 | ``` 75 | 76 | ![](http://ww3.sinaimg.cn/mw690/baa3278fgw1ey7ky56nbgj20n60fuaav.jpg) 77 | 78 | ### Options 79 | 80 | You can set custom options for Reminder. Run: 81 | 82 | php artisan vendor:publish 83 | 84 | to publish the config file for reminder. 85 | 86 | You can see [toastr's documentation](http://codeseven.github.io/toastr/demo.html) to custom your need. 87 | 88 | ### MIT 89 | -------------------------------------------------------------------------------- /src/Reminder.php: -------------------------------------------------------------------------------- 1 | session = $session; 40 | $this->config = $config; 41 | } 42 | 43 | /** 44 | * build the script tag. 45 | * 46 | * @return string 47 | */ 48 | public function message() 49 | { 50 | $messages = $this->session->get('reminder::messages'); 51 | if (! $messages) $messages = []; 52 | 53 | $script = ''; 75 | 76 | return $script; 77 | } 78 | 79 | /** 80 | * Add a flash message to session. 81 | * 82 | * @param string $type Must be one of info, success, warning, error. 83 | * @param string $message The flash message content. 84 | * @param string $title The flash message title. 85 | * @param array $options The custom options. 86 | * 87 | * @return void 88 | */ 89 | public function add($type, $message, $title = null, $options = []) 90 | { 91 | $types = ['error', 'info', 'success', 'warning']; 92 | 93 | if (! in_array($type, $types)) { 94 | throw new Exception("The $type remind message is not valid."); 95 | } 96 | 97 | $this->messages[] = [ 98 | 'type' => $type, 99 | 'title' => $title, 100 | 'message' => $message, 101 | 'options' => $options, 102 | ]; 103 | 104 | $this->session->flash('reminder::messages', $this->messages); 105 | } 106 | 107 | /** 108 | * Add an info flash message to session. 109 | * 110 | * @param string $message The flash message content. 111 | * @param string $title The flash message title. 112 | * @param array $options The custom options. 113 | * 114 | * @return void 115 | */ 116 | public function info($message, $title = null, $options = []) 117 | { 118 | $this->add('info', $message, $title, $options); 119 | } 120 | 121 | /** 122 | * Add a success flash message to session. 123 | * 124 | * @param string $message The flash message content. 125 | * @param string $title The flash message title. 126 | * @param array $options The custom options. 127 | * 128 | * @return void 129 | */ 130 | public function success($message, $title = null, $options = []) 131 | { 132 | $this->add('success', $message, $title, $options); 133 | } 134 | 135 | /** 136 | * Add an warning flash message to session. 137 | * 138 | * @param string $message The flash message content. 139 | * @param string $title The flash message title. 140 | * @param array $options The custom options. 141 | * 142 | * @return void 143 | */ 144 | public function warning($message, $title = null, $options = []) 145 | { 146 | $this->add('warning', $message, $title, $options); 147 | } 148 | 149 | /** 150 | * Add an error flash message to session. 151 | * 152 | * @param string $message The flash message content. 153 | * @param string $title The flash message title. 154 | * @param array $options The custom options. 155 | * 156 | * @return void 157 | */ 158 | public function error($message, $title = null, $options = []) 159 | { 160 | $this->add('error', $message, $title, $options); 161 | } 162 | } 163 | --------------------------------------------------------------------------------