在 laravel 5.1 中获取完整网址
Get fullUrl in laravel 5.1
我有多个 bootstrap 选项卡,其中每个选项卡都执行与其他选项卡不同的操作,例如
app-url/users#creat-admin-users-tab
app-url/users#creat-regular-users-tab
在 Laravel 中有什么方法可以得到完整的 url 包括#tab-name
感谢您的宝贵时间。
Laravel 具有 return 当前 url 的功能。全部在本页指定:http://laravel.com/api/5.0/Illuminate/Http/Request.html
您要找的是Request::fullUrl()
。
假设我在 http://laravel.dev/test?test=1,这里是方法和结果:
Request::fullUrl()
// Returns: http://laravel.dev/test?test=1
Request::url()
// Returns: http://laravel.dev/test
Request::path()
// Returns: test
Request::root()
// Returns: http://laravel.dev
检查以下内容
$_SERVER['HTTP_HOST'] => Host name from the current request.
$_SERVER['HTTP'] => Set to a non-empty value if the protocol is HTTP
$_SERVER['HTTPS'] => Set to a non-empty value if the protocol is HTTPS
$_SERVER["SERVER_PORT"] => Server port. Default is: 80
$_SERVER['REQUEST_URI'] => The URI to access this page;
这是真的 - 目前获得“#”的唯一方法是使用 js,例如像这样:
var hash = window.location.hash;
var tabName1 = '#creat-admin-users-tab';
var tabName2 = '#creat-regular-users-tab';
if (hash.indexOf(tabName1) !== -1) console.log("It's creat-admin-users-tab");
else if (hash.indexOf(tabName2) !== -1) console.log("It's creat-regular-users-tab");
这可以帮助您 url 的其他部分(将其添加到您的路由文件中):
use Illuminate\Http\Request;
Route::get('/app-url/users', function (Request $request) {
$fullUrl = $request->fullUrl();
var_dump($fullUrl);
});
我有多个 bootstrap 选项卡,其中每个选项卡都执行与其他选项卡不同的操作,例如
app-url/users#creat-admin-users-tab
app-url/users#creat-regular-users-tab
在 Laravel 中有什么方法可以得到完整的 url 包括#tab-name
感谢您的宝贵时间。
Laravel 具有 return 当前 url 的功能。全部在本页指定:http://laravel.com/api/5.0/Illuminate/Http/Request.html
您要找的是Request::fullUrl()
。
假设我在 http://laravel.dev/test?test=1,这里是方法和结果:
Request::fullUrl()
// Returns: http://laravel.dev/test?test=1
Request::url()
// Returns: http://laravel.dev/test
Request::path()
// Returns: test
Request::root()
// Returns: http://laravel.dev
检查以下内容
$_SERVER['HTTP_HOST'] => Host name from the current request.
$_SERVER['HTTP'] => Set to a non-empty value if the protocol is HTTP
$_SERVER['HTTPS'] => Set to a non-empty value if the protocol is HTTPS
$_SERVER["SERVER_PORT"] => Server port. Default is: 80
$_SERVER['REQUEST_URI'] => The URI to access this page;
这是真的 - 目前获得“#”的唯一方法是使用 js,例如像这样:
var hash = window.location.hash;
var tabName1 = '#creat-admin-users-tab';
var tabName2 = '#creat-regular-users-tab';
if (hash.indexOf(tabName1) !== -1) console.log("It's creat-admin-users-tab");
else if (hash.indexOf(tabName2) !== -1) console.log("It's creat-regular-users-tab");
这可以帮助您 url 的其他部分(将其添加到您的路由文件中):
use Illuminate\Http\Request;
Route::get('/app-url/users', function (Request $request) {
$fullUrl = $request->fullUrl();
var_dump($fullUrl);
});