Get fullUrl in laravel 5.1

心已入冬 提交于 2019-11-29 02:37:04

问题


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

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

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

Thanks for your time.


回答1:


Check the following

$_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;




回答2:


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

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

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

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 



回答3:


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

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):

use Illuminate\Http\Request;

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


来源:https://stackoverflow.com/questions/33687496/get-fullurl-in-laravel-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!