我是 laravel 的初學者,我想在頁面上顯示當前頁面的實時 URL。// 完整的 URL,帶有查詢字符串 $request->fullUrl()// 只是 URL 的路徑部分 $request->path()// 只是 URL 的根(協議和域)部分) $request->r強調文本oot()在谷歌上搜索后我發現了這個,誰能告訴我這是否是正確的方法,如果它是如何實現的。比如在“ Routes ”中寫什么,在“ controller ”中寫什么。
2 回答

千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
從文檔:
// Get the current URL without the query string...
echo url()->current();
// Get the current URL including the query string...
echo url()->full();
這些方法中的每一個也可以通過 URL 外觀訪問:
use Illuminate\Support\Facades\URL;
echo URL::current();
如果您使用命名路由(非強制性):
echo route('post.show', ['post' => 1]);
// http://example.com/post/1

呼喚遠方
TA貢獻1856條經驗 獲得超11個贊
獲取完整、當前和以前的 URL
// Get the current URL without the query string...
echo url()->current();
// Get the current URL including the query string...
echo url()->full();
// Get the full URL for the previous request...
echo url()->previous();
獲取特定的 URL 段
{{ Request::segment(1) }}
- 2 回答
- 0 關注
- 236 瀏覽
添加回答
舉報
0/150
提交
取消