Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get relative URLs with url() in Laravel 5.2?

I have done searches and cannot find anything that solves this in Laravel 5.2.

Is it possible to generate relative URLs in Laravel 5.2?

Meaning, instead of http://example.com/mypage I get simply /mypage ?

like image 572
Martin Avatar asked Feb 18 '16 19:02

Martin


2 Answers

If you are trying to generate them, rather than retrieve the current one, you can pass a 3rd parameter to the route function.

echo route('about', [], false);

If you pass true (the default) as the 3rd parameter it will give you

http://example.com/about

If you pass false as the 3rd parameter it will give you

/about

like image 56
Andrew Brown Avatar answered Oct 28 '22 16:10

Andrew Brown


Yes, you should use $request->path(), it will return the URI.

like image 40
user2094178 Avatar answered Oct 28 '22 16:10

user2094178