Skip to content

Commit 1ae68f9

Browse files
committed
2 parents 3bf24bb + 817810c commit 1ae68f9

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,17 @@ php artisan vendor:publish --provider="JamesMills\LaravelTimezone\LaravelTimezon
108108

109109
### Flash Messages
110110

111-
By default, when the timezone has been set, there is a flash message set in the session. There is an optional integration to use [laracasts/flash](https://github.com/laracasts/flash) package if you wish. Just publish the config and override the default `'flash' => 'laracasts'` settings.
111+
When the timezone has been set, we display a flash message, By default, is configured to use Laravel default flash messaging, here are some of the optional integrations.
112+
113+
[laracasts/flash](https://github.com/laracasts/flash) - `'flash' => 'laracasts'`
114+
115+
[mercuryseries/flashy](https://github.com/mercuryseries/flashy) - `'flash' => 'mercuryseries'`
116+
117+
[spatie/laravel-flash](https://github.com/spatie/laravel-flash) - `'flash' => 'spatie'`
118+
119+
[mckenziearts/laravel-notify](https://github.com/mckenziearts/laravel-notify) - `'flash' => 'mckenziearts'`
120+
121+
To override this configuration, you just need to change the `flash` property inside the configuration file `config/timezone.php` for the desired package.
112122

113123
### Overwrite existing timezones in the database
114124

src/Listeners/Auth/UpdateUsersTimezone.php

+42-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,53 @@ public function handle(Login $event)
2424
$user->timezone = $geoip_info['timezone'];
2525
$user->save();
2626

27-
if (config('timezone.flash') == 'laracasts') {
28-
flash()->success('We have set your timezone to ' . $geoip_info['timezone']);
29-
} else {
30-
request()->session()->flash('success', 'We have set your timezone to ' . $geoip_info['timezone']);
31-
}
27+
$this->notify($geoip_info);
3228
}
3329
}
3430
}
3531

3632
/**
33+
* @param \Torann\GeoIP\Location $geoip_info
34+
*/
35+
public function notify(\Torann\GeoIP\Location $geoip_info)
36+
{
37+
if (config('timezone.flash') == 'off') {
38+
return;
39+
}
40+
41+
$message = 'We have set your timezone to ' . $geoip_info['timezone'];
42+
43+
if (config('timezone.flash') == 'laravel') {
44+
request()->session()->flash('success', $message);
45+
46+
return;
47+
}
48+
49+
if (config('timezone.flash') == 'laracasts') {
50+
flash()->success($message);
51+
52+
return;
53+
}
54+
55+
if (config('timezone.flash') == 'mercuryseries') {
56+
flashy()->success($message);
57+
58+
return;
59+
}
60+
61+
if (config('timezone.flash') == 'spatie') {
62+
flash()->success($message);
63+
64+
return;
65+
}
66+
67+
if (config('timezone.flash') == 'mckenziearts') {
68+
notify()->success($message);
69+
70+
return;
71+
}
72+
73+
/**
3774
* @return mixed
3875
*/
3976
public function getFromLookup()

src/config/timezone.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
|
1010
| Here you may configure if to use the laracasts/flash package for flash
1111
| notifications when a users timezone is set.
12-
| options [standard, laracasts]
12+
| options [laravel, laracasts, mercuryseries, spatie, mckenziearts]
1313
|
1414
*/
1515

16-
'flash' => 'standard',
16+
'flash' => 'laravel',
1717

1818
/*
1919
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)