在laravel 5.1中获得fullUrl

时间:2015-11-13 07:07:49

标签: php laravel laravel-5 laravel-routing

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

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

Laravel有没有办法获得包含#tab-name

的完整网址?

感谢您的时间。

3 个答案:

答案 0 :(得分:61)

Laravel具有返回当前网址的功能。这一切都在此页面中指定: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 

答案 1 :(得分:5)

检查以下

$_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 :(得分:3)

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

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

use Illuminate\Http\Request;

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