Laravel - How to get current url in laravel controller and view
Most of the times when we develop a project, we need a current URL of application like for ajax pagination, to reload current page, redirection purpose and other places in project.
You can easily get current url in laravel 5, laravel 6, laravel 7 and laravel 8 application.
To get current URL laravel provides url helper. With the help of this url helper we can get information about the current URL.
To get current URL
echo url()->current();
To get current URL with query string
echo url()->full();
To get URL of previous request URL
echo url()->previous();
To get current URL in view blade file
{{ url()->current() }}
All of the above methods can be accessed via URL facade. Check below example
use IlluminateSupportFacadesURL; echo URL::current();
Created At: 22 December, 2024
Views: 1,629
Social Sharing
Search
Articles
Recently Added Jobs
Rajasthan High Court - Jodhpur Recruitment 2017 for Civil Judges
Last Date: 21 December, 2017
Last Date: 21 December, 2017
WBSEDCL Recruitment - 2017 for Office Executive
Last Date: 16 May, 2017
Last Date: 16 May, 2017
RECRUITMENT OF PROBATIONARY OFFICERS IN STATE BANK OF INDIA
Last Date: 06 March, 2017
Last Date: 06 March, 2017
UPSC Combined Medical Services Examination 2015
Last Date: 10 April, 2015
Last Date: 10 April, 2015
UPSC Engineering Services Examination 2015
Last Date: 10 April, 2015
Last Date: 10 April, 2015