Lấy đường dẫn URL hiện tại trên Laravel 0 (0)

Lấy đường dẫn URL hiện tại trên Laravel 0 (0)

Learn more »

Để lấy đường dẫn URL hiện tại của Laravel, Class Request của Laravel cung cấp cho chúng ta các phương thức để thao tác với URL như sau:

Chú ý: Các phương thức này là của Laravel 7

VD: Chúng ta có biến $request là 1 instance của Class Request trong Laravel

  • $request = new Request();

Lấy đường dẫn URL hiện tại với không chuỗi truy vấn (Query String)

  • $currentUrl = $request->current();

Lấy đường dẫn toàn bộ URL hiện tại với chuỗi truy vấn (Query String)

  • $currentUrl = $request->full();

Với Laravel 6 thì là

  • $currentUrl = $request->fullUrl();

Lấy đường dẫn toàn bộ URL query trước đó (referer URL)

  • $preUrl = $request->previous();

Lấy một thành phần của URL

  • $preUrl = $request->segment(3);

Ngoài ra bạn có thể lấy thông tin URL hiện tại bằng PHP ở đây

Nguồn; vinasupport.com


All the options and events can be found in official documentation

Integrations
Users

Share Profile

Anyone at KeenThemes can view
Anyone with link can edit

Give Award

Anyone at KeenThemes can view
Anyone with link can edit

Report User

Let us know why you’re reporing this person
Don't worry, your report is completely anonymous; the person you're
reporting will not be informed that you've submitted it