imple question, but the answer seems quite hard to come by. In Codeigniter, I could load the url helper and then simply do
echo base_url();
to get my site's URL. Is there an equivalent in Laravel?
欢迎各位兄弟 发布技术文章
这里的技术是共享的
add a comment |
155 | You can get the base url of the Laravel application by:
or
Read more about Laravel helpers here
So you can do:
You can also use the application container:
Or inject the UrlGenerator:
| ||
61 | Laravel < 5.2
Laravel >= 5.2
Hope this helps you | ||||||||||||||||
|
25 | For Laravel 5 I normally use:
I'm of the understanding that using the | ||||||||||||||||
|
10 | To get it to work with non-pretty URLs I had to do:
| ||||
|
10 | Laravel provides bunch of helper functions and for your requirement you can simply use url() function of Laravel Helpers but in case of Laravel 5.2 you will have to use url('/') here is the list of all other helper functions of Laravel | ||||
|
5 | echo url('/'); echo asset('/'); both displayed the home url in my case :) | ||
2 | Another possibility: | ||||||||
|
1 | To just get the app url, that you configured you can use Config::get('app.url') | ||||||||
|
1 | I used this and it worked for me in Laravel 5.3.18:
IMPORTANT NOTE: This will only work when you have already removed "public" from your URL. To do this, you may check out this helpful tutorial. | |||
1 | By the way, if your route has a name like:
You can use the
Other useful functions:
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php | |||
0 | You can also use URL::to('/') to display image in Laravel. Please see below:
Assume that, your image is stored under "public/images". | ||
/something/
it'll make the right URL. – ceejayoz Apr 14 '14 at 12:42