Skip to content

Commit d95fbff

Browse files
authored
Merge pull request #1 from kyledoesdev/feature/V0.0.2
V0.0.2
2 parents f8db9a0 + d1beccc commit d95fbff

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
],
1818
"require": {
1919
"php": "^8.4",
20-
"spatie/laravel-package-tools": "^1.16",
2120
"illuminate/contracts": "^12.0",
2221
"illuminate/support": "^12.0",
2322
"illuminate/http": "^12.0",
24-
"guzzlehttp/guzzle": "^7.8"
23+
"spatie/laravel-package-tools": "^1.16"
2524
},
2625
"require-dev": {
2726
"laravel/pint": "^1.14",
@@ -72,4 +71,4 @@
7271
},
7372
"minimum-stability": "dev",
7473
"prefer-stable": true
75-
}
74+
}

src/Libraries/helpers.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,28 @@ function timezone(): string
1414
return $tz;
1515
}
1616

17-
$response = Http::get('http://ip-api.com/json/'.request()->ip());
17+
$response = Http::timeout(3)
18+
->retry(1, 200)
19+
->get('http://ip-api.com/json/'.request()->ip());
1820

1921
return $response->successful()
2022
? $response->json('timezone', $tz)
2123
: $tz;
2224
}
2325
}
26+
27+
if (! function_exists('zuck')) {
28+
/**
29+
* Get the user packet data
30+
*/
31+
function user_packet(): array
32+
{
33+
$response = Http::timeout(3)
34+
->retry(1, 200)
35+
->get('http://ip-api.com/json/'.request()->ip());
36+
37+
return $response->successful()
38+
? $response->json()
39+
: [];
40+
}
41+
}

src/Providers/MacroServiceProvider.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ class MacroServiceProvider extends ServiceProvider
1010
public function boot(): void
1111
{
1212
Carbon::macro('inUserTimezone', function () {
13-
$user = auth()->user();
14-
15-
return $this->tz($user?->timezone ?? timezone());
13+
$timezone = auth()->user()?->timezone ?? session()->get('____tz');
14+
15+
if (is_null($timezone)) {
16+
$timezone = timezone();
17+
18+
session()->put(['____tz' => $timezone]);
19+
}
20+
21+
return $this->tz($timezone);
1622
});
1723
}
1824
}

0 commit comments

Comments
 (0)