Skip to content

Commit 5702317

Browse files
committed
add helper for current app url with port
1 parent 991b787 commit 5702317

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

config/sanctum.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Laravel\Sanctum\Sanctum;
4+
35
return [
46

57
/*
@@ -16,7 +18,7 @@
1618
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
1719
'%s%s',
1820
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
19-
env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : ''
21+
Sanctum::currentApplicationUrlWithPort(),
2022
))),
2123

2224
/*

src/Sanctum.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ class Sanctum
2727
*/
2828
public static $runsMigrations = true;
2929

30+
/**
31+
* Get the current application URL from the "APP_URL" environment variable - with port.
32+
*
33+
* @return string
34+
*/
35+
public static function currentApplicationUrlWithPort()
36+
{
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) : '') : '';
38+
}
39+
3040
/**
3141
* Set the current user for the application with the given abilities.
3242
*

0 commit comments

Comments
 (0)