How to use URL Facade in Laravel

Categorized as Laravel

Laravel quick tip! URL Facade is a cool feature in Laravel that allows you to extract the current, previous, and full URLs on any given web page. See the example below:

use Illuminate\Support\Facades\URL;

// This one will give us the current url but will not include any query params:

URL::current();  

https://coursecomp.com/user/admin/

// This one gives us the query parameters

URL::full();

https://coursecomp.com/user/admin/?foo=bar

// This one gives the previous url that we visited.
// For example, I visited https://coursecomp.com/news/ 
// before visiting https://coursecomp.com/user/admin/?foo=bar

URL::previous();

https://coursecomp.com/news/

Leave a reply

Your email address will not be published.