Skip to content

Commit dc5d749

Browse files
committed
use config function
1 parent 1c61d9a commit dc5d749

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Sanctum.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class Sanctum
3434
*/
3535
public static function currentApplicationUrlWithPort()
3636
{
37-
return env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST).(parse_url(env('APP_URL'), PHP_URL_PORT) ? ':'.parse_url(env('APP_URL'), PHP_URL_PORT) : '') : '';
37+
$appUrl = config('app.url');
38+
39+
return $appUrl ? ','.parse_url($appUrl, PHP_URL_HOST).(parse_url($appUrl, PHP_URL_PORT) ? ':'.parse_url($appUrl, PHP_URL_PORT) : '') : '';
3840
}
3941

4042
/**

tests/DefaultConfigContainsAppUrlTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class DefaultConfigContainsAppUrlTest extends TestCase
1111
protected function getEnvironmentSetUp($app)
1212
{
1313
putenv('APP_URL=https://www.example.com');
14+
$app['config']->set('app.url', 'https://www.example.com');
15+
1416
$config = require __DIR__.'/../config/sanctum.php';
1517

1618
$app['config']->set('sanctum.stateful', $config['stateful']);
@@ -28,18 +30,22 @@ public function test_default_config_contains_app_url()
2830
public function test_app_url_is_not_parsed_when_missing_from_env()
2931
{
3032
putenv('APP_URL');
33+
config(['app.url' => null]);
3134

3235
$config = require __DIR__.'/../config/sanctum.php';
3336

3437
$this->assertNull(env('APP_URL'));
3538
$this->assertNotContains('', $config['stateful']);
39+
40+
putenv('APP_URL=https://www.example.com');
41+
config(['app.url' => 'https://www.example.com']);
3642
}
3743

3844
public function test_request_from_app_url_is_stateful_with_default_config()
3945
{
4046
$request = Request::create('/');
4147

42-
$request->headers->set('referer', env('APP_URL'));
48+
$request->headers->set('referer', config('app.url'));
4349

4450
$this->assertTrue(EnsureFrontendRequestsAreStateful::fromFrontend($request));
4551
}

0 commit comments

Comments
 (0)