php 在 Laravel 5.1 中获取 fullUrl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33687496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:35:08  来源:igfitidea点击:

Get fullUrl in laravel 5.1

phplaravellaravel-5laravel-routing

提问by Just User

i have multiple bootstrap tabs where each one do different action from others tabs for exmaple

我有多个引导程序选项卡,其中每个选项卡都与其他选项卡执行不同的操作,例如

app-url/users#creat-admin-users-tabapp-url/users#creat-regular-users-tab

app-url/users#creat-admin-users-tabapp-url/users#creat-regular-users-tab

Is there any way in Laravel to get full url including the #tab-name

Laravel 有什么方法可以获取完整的 url,包括 #tab-name

Thanks for your time.

谢谢你的时间。

采纳答案by Just User

Check the following

检查以下内容

$_SERVER['HTTP_HOST'] => Host name from the current request.

$_SERVER['HTTP_HOST'] => Host name from the current request.

$_SERVER['HTTP'] => Set to a non-empty value if the protocol is HTTP

$_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['HTTPS'] => Set to a non-empty value if the protocol is HTTPS

$_SERVER["SERVER_PORT"] => Server port. Default is: 80

$_SERVER["SERVER_PORT"] => Server port. Default is: 80

$_SERVER['REQUEST_URI'] => The URI to access this page;

$_SERVER['REQUEST_URI'] => The URI to access this page;

回答by Andrius

Laravel has functionality to return you the current url. It is all specified in this page: http://laravel.com/api/5.0/Illuminate/Http/Request.html

Laravel 具有返回当前 url 的功能。都是在这个页面指定的:http: //laravel.com/api/5.0/Illuminate/Http/Request.html

What you are looking for is Request::fullUrl().

您正在寻找的是Request::fullUrl().

Let's say I'm on http://laravel.dev/test?test=1, here are the methods and the results:

假设我在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 

回答by tsveti_iko

It's true - the only way to get the "#" for now is to use js e.g. like this:

这是真的 - 现在获得“#”的唯一方法是使用 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");

And this can help you for the other parts of the url (add it in your route file):

这可以帮助您处理 url 的其他部分(将其添加到您的路由文件中):

use Illuminate\Http\Request;

Route::get('/app-url/users', function (Request $request) {
    $fullUrl = $request->fullUrl();
    var_dump($fullUrl);
});