├── tests
├── .gitkeep
└── FlashyTest.php
├── .gitignore
├── .travis.yml
├── src
├── MercurySeries
│ └── Flashy
│ │ ├── SessionStore.php
│ │ ├── Flashy.php
│ │ ├── functions.php
│ │ ├── LaravelSessionStore.php
│ │ ├── FlashyServiceProvider.php
│ │ └── FlashyNotifier.php
└── views
│ └── message.blade.php
├── phpunit.xml
├── composer.json
└── readme.md
/tests/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.phar
3 | composer.lock
4 | .DS_Store
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 | - 5.5
7 | - 5.6
8 | - hhvm
9 |
10 | before_script:
11 | - composer self-update
12 | - composer install --prefer-source --no-interaction --dev
13 |
14 | script: phpunit
15 |
--------------------------------------------------------------------------------
/src/MercurySeries/Flashy/SessionStore.php:
--------------------------------------------------------------------------------
1 | success($message, $link);
17 | }
18 |
19 | return $notifier;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | ./tests/
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/MercurySeries/Flashy/LaravelSessionStore.php:
--------------------------------------------------------------------------------
1 | session = $session;
21 | }
22 |
23 | /**
24 | * Flash a message to the session.
25 | *
26 | * @param $name
27 | * @param $data
28 | */
29 | public function flashy($name, $data)
30 | {
31 | $this->session->flash($name, $data);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mercuryseries/flashy",
3 | "description": "Easy flash notifications",
4 | "license": "MIT",
5 | "authors": [
6 | {
7 | "name": "Honoré Hounwanou",
8 | "email": "mercuryseries@gmail.com"
9 | }
10 | ],
11 | "require": {
12 | "php": ">=5.4.0",
13 | "illuminate/support": "~5.0|~6.0|~7.0|~8.0|~9.0|~10.0"
14 | },
15 | "require-dev": {
16 | "mockery/mockery": "dev-master"
17 | },
18 | "autoload": {
19 | "psr-0": {
20 | "MercurySeries\\Flashy": "src/"
21 | },
22 | "files": [
23 | "src/MercurySeries/Flashy/functions.php"
24 | ]
25 | },
26 | "minimum-stability": "stable",
27 | "extra" : {
28 | "laravel" : {
29 | "providers" : [
30 | "MercurySeries\\Flashy\\FlashyServiceProvider"
31 | ],
32 | "aliases": {
33 | "Flashy": "MercurySeries\\Flashy\\Flashy"
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/MercurySeries/Flashy/FlashyServiceProvider.php:
--------------------------------------------------------------------------------
1 | app->bind(
25 | \MercurySeries\Flashy\SessionStore::class,
26 | \MercurySeries\Flashy\LaravelSessionStore::class
27 | );
28 |
29 | $this->app->singleton('flashy', function () {
30 | return $this->app->make(\MercurySeries\Flashy\FlashyNotifier::class);
31 | });
32 | }
33 |
34 | /**
35 | * Bootstrap the application events.
36 | *
37 | * @return void
38 | */
39 | public function boot()
40 | {
41 | $this->loadViewsFrom(__DIR__ . '/../../views', 'flashy');
42 |
43 | $this->publishes([
44 | __DIR__ . '/../../views' => base_path('resources/views/vendor/flashy')
45 | ]);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/views/message.blade.php:
--------------------------------------------------------------------------------
1 |
86 |
87 |
99 |
100 | @if(Session::has('flashy_notification.message'))
101 |
106 |
107 |
110 | @endif
--------------------------------------------------------------------------------
/src/MercurySeries/Flashy/FlashyNotifier.php:
--------------------------------------------------------------------------------
1 | session = $session;
23 | }
24 |
25 | /**
26 | * Flash an information message.
27 | *
28 | * @param string $message
29 | * @param string $link
30 | */
31 | public function info($message, $link = '#')
32 | {
33 | $this->message($message, $link, 'info');
34 |
35 | return $this;
36 | }
37 |
38 | /**
39 | * Flash a success message.
40 | *
41 | * @param string $message
42 | * @param string $link
43 | * @return $this
44 | */
45 | public function success($message, $link = '#')
46 | {
47 | $this->message($message, $link, 'success');
48 |
49 | return $this;
50 | }
51 |
52 | /**
53 | * Flash an error message.
54 | *
55 | * @param string $message
56 | * @param string $link
57 | * @return $this
58 | */
59 | public function error($message, $link = '#')
60 | {
61 | $this->message($message, $link, 'error');
62 |
63 | return $this;
64 | }
65 |
66 | /**
67 | * Flash a warning message.
68 | *
69 | * @param string $message
70 | * @param string $link
71 | * @return $this
72 | */
73 | public function warning($message, $link = '#')
74 | {
75 | $this->message($message, $link, 'warning');
76 |
77 | return $this;
78 | }
79 |
80 | /**
81 | * Flash a primary message.
82 | *
83 | * @param string $message
84 | * @param string $link
85 | * @return $this
86 | */
87 | public function primary($message, $link = '#')
88 | {
89 | $this->message($message, $link, 'primary');
90 |
91 | return $this;
92 | }
93 |
94 | /**
95 | * Flash a primary dark message.
96 | *
97 | * @param string $message
98 | * @param string $link
99 | * @return $this
100 | */
101 | public function primaryDark($message, $link = '#')
102 | {
103 | $this->message($message, $link, 'primary-dark');
104 |
105 | return $this;
106 | }
107 |
108 | /**
109 | * Flash a muted message.
110 | *
111 | * @param string $message
112 | * @param string $link
113 | * @return $this
114 | */
115 | public function muted($message, $link = '#')
116 | {
117 | $this->message($message, $link, 'muted');
118 |
119 | return $this;
120 | }
121 |
122 | /**
123 | * Flash a muted dark message.
124 | *
125 | * @param string $message
126 | * @param string $link
127 | * @return $this
128 | */
129 | public function mutedDark($message, $link = '#')
130 | {
131 | $this->message($message, $link, 'muted-dark');
132 |
133 | return $this;
134 | }
135 |
136 | /**
137 | * Flash a general message.
138 | *
139 | * @param string $message
140 | * @param string $link
141 | * @param string $type
142 | * @return $this
143 | */
144 | public function message($message, $link = '#', $type = 'success')
145 | {
146 | $this->session->flashy('flashy_notification.message', $message);
147 | $this->session->flashy('flashy_notification.link', $link);
148 | $this->session->flashy('flashy_notification.type', $type);
149 |
150 | return $this;
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/tests/FlashyTest.php:
--------------------------------------------------------------------------------
1 | session = m::mock('MercurySeries\Flashy\SessionStore');
15 | $this->flashy = new FlashyNotifier($this->session);
16 | }
17 |
18 | /** @test */
19 | public function it_displays_default_flashy_notifications()
20 | {
21 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Welcome Aboard');
22 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
23 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'success');
24 |
25 | $this->flashy->message('Welcome Aboard');
26 | }
27 |
28 | /** @test */
29 | public function it_displays_info_flashy_notifications()
30 | {
31 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Welcome Aboard');
32 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
33 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'info');
34 |
35 | $this->flashy->info('Welcome Aboard');
36 | }
37 |
38 | /** @test */
39 | public function it_displays_success_flashy_notifications()
40 | {
41 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Welcome Aboard');
42 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
43 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'success');
44 |
45 | $this->flashy->success('Welcome Aboard');
46 | }
47 |
48 | /** @test */
49 | public function it_displays_error_flashy_notifications()
50 | {
51 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Uh Oh');
52 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
53 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'error');
54 |
55 | $this->flashy->error('Uh Oh');
56 | }
57 |
58 | /** @test */
59 | public function it_displays_warning_flashy_notifications()
60 | {
61 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Be careful!');
62 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
63 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'warning');
64 |
65 | $this->flashy->warning('Be careful!');
66 | }
67 |
68 | /** @test */
69 | public function it_displays_primary_flashy_notifications()
70 | {
71 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Thanks for signing up!');
72 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
73 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'primary');
74 |
75 | $this->flashy->primary('Thanks for signing up!');
76 | }
77 |
78 | /** @test */
79 | public function it_displays_primary_dark_flashy_notifications()
80 | {
81 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Thanks for signing up!');
82 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
83 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'primary-dark');
84 |
85 | $this->flashy->primaryDark('Thanks for signing up!');
86 | }
87 |
88 | /** @test */
89 | public function it_displays_muted_flashy_notifications()
90 | {
91 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Can you see me?');
92 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
93 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'muted');
94 |
95 | $this->flashy->muted('Can you see me?');
96 | }
97 |
98 | /** @test */
99 | public function it_displays_muted_dark_flashy_notifications()
100 | {
101 | $this->session->shouldReceive('flashy')->with('flashy_notification.message', 'Can you see me?');
102 | $this->session->shouldReceive('flashy')->with('flashy_notification.link', '#');
103 | $this->session->shouldReceive('flashy')->with('flashy_notification.type', 'muted-dark');
104 |
105 | $this->flashy->mutedDark('Can you see me?');
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Easy Flash Messages
2 |
3 | 
4 |
5 | # Copyright
6 | Inspired by [Jeffrey Way's Flash Package](https://github.com/laracasts/flash). Added following Jeffrey Ωmega's request.
7 |
8 | ## Installation
9 |
10 | ### Video Tutorial
11 |
12 | [Watch a Video Tutorial here](https://www.youtube.com/watch?v=GXMLd7F9o94)
13 |
14 | ### You like text ?
15 |
16 | First, pull in the package through Composer.
17 |
18 | Run `composer require mercuryseries/flashy`
19 |
20 | And then, if using Laravel 5, include the service provider within `config/app.php`.
21 |
22 | ```php
23 | 'providers' => [
24 | MercurySeries\Flashy\FlashyServiceProvider::class,
25 | ];
26 | ```
27 |
28 | And, for convenience, add a facade alias to this same file at the bottom:
29 |
30 | ```php
31 | 'aliases' => [
32 | 'Flashy' => MercurySeries\Flashy\Flashy::class,
33 | ];
34 | ```
35 |
36 | ## Usage
37 |
38 | Within your controllers, before you perform a redirect...
39 |
40 | ```php
41 | public function store()
42 | {
43 | Flashy::message('Welcome Aboard!', 'http://your-awesome-link.com');
44 |
45 | return Redirect::home();
46 | }
47 | ```
48 |
49 | You may also do:
50 |
51 | - `Flashy::info('Message', 'http://your-awesome-link.com')`
52 | - `Flashy::success('Message', 'http://your-awesome-link.com')`
53 | - `Flashy::error('Message', 'http://your-awesome-link.com')`
54 | - `Flashy::warning('Message', 'http://your-awesome-link.com')`
55 | - `Flashy::primary('Message', 'http://your-awesome-link.com')`
56 | - `Flashy::primaryDark('Message', 'http://your-awesome-link.com')`
57 | - `Flashy::muted('Message', 'http://your-awesome-link.com')`
58 | - `Flashy::mutedDark('Message', 'http://your-awesome-link.com')`
59 |
60 | Again, if using Laravel, this will set a few keys in the session:
61 |
62 | - 'flashy_notification.message' - The message you're flashing
63 | - 'flashy_notification.type' - A string that represents the type of notification (good for applying HTML class names)
64 | - 'flashy_notification.link' - The URL to redirect to on click
65 |
66 | Alternatively, again, if you're using Laravel, you may reference the `flashy()` helper function, instead of the facade. Here's an example:
67 |
68 | ```php
69 | /**
70 | * Destroy the user's session (logout).
71 | *
72 | * @return Response
73 | */
74 | public function destroy()
75 | {
76 | Auth::logout();
77 |
78 | flashy()->success('You have been logged out.', 'http://your-awesome-link.com');
79 |
80 | return home();
81 | }
82 | ```
83 |
84 | Or, for a general information flash, just do: `flashy('Some message', 'http://your-awesome-link.com');`.
85 |
86 | With this message flashed to the session, you may now display it in your view(s). Maybe something like:
87 |
88 | ```html
89 | @if(Session::has('flashy_notification.message'))
90 |
96 |
97 |
100 | @endif
101 | ```
102 |
103 | Because flash messages are so common, if you want, you may use (or modify) the views that are included with this package. Simply append to your layout view:
104 |
105 | ```html
106 | @include('flashy::message')
107 | ```
108 |
109 | > Note that this package has jQuery has dependency. It's also better to load flashy before your body close tag.
110 |
111 | ## Example
112 |
113 | ```html
114 |
115 |
116 |
117 |
118 | Document
119 |
120 |
121 |
122 |
123 |
124 |
Welcome to my website...
125 |
126 |
127 |
128 | @include('flashy::message')
129 |
130 |
131 | ```
132 |
133 | If you need to modify the flash message partials, you can run:
134 |
135 | ```bash
136 | php artisan vendor:publish
137 | ```
138 |
139 | The two package views will now be located in the `app/views/packages/mercuryseries/flashy/` directory.
140 |
141 | ```php
142 | Flashy::message('Welcome aboard!', 'http://your-awesome-link.com');
143 |
144 | return Redirect::home();
145 | ```
146 |
147 | ```php
148 | Flashy::error('Sorry! Please try again.', 'http://your-awesome-link.com');
149 |
150 | return Redirect::home();
151 | ```
152 |
153 | ## Nice rendering
154 |
155 | For a nice rendering you may include these lines in your head:
156 |
157 | ```html
158 |
159 |
160 | ```
161 |
162 | and override the following sections of the default flashy view:
163 |
164 | ```html
165 |
178 |
179 |
185 | ```
186 |
187 |
--------------------------------------------------------------------------------