问题很简单,但答案似乎很难得到。在Codeigniter中,我可以加载URL助手,然后简单地执行

echo base_url();

获取我网站的URL。在Laravel中也有类似的情况吗?


当前回答

有多种方法:

请求()- > getSchemeAndHttpHost () url(“/”) 资产(“) 配置(“app.url”) $ _SERVER(“SERVER_NAME”)

其他回答

你可以从laravel 5的请求处得到

request()->getSchemeAndHttpHost();

看看这个——

<a href="{{url('/abc/xyz')}}">Go</a>

这对我很有用,我希望对你也有用。

顺便说一下,如果你的路线有一个这样的名字:

Route::match(['get', 'post'], 'specialWay/edit', 'SpecialwayController@edit')->name('admin.spway.edit');

你可以像这样使用route()函数:

<form method="post" action="{{route('admin.spway.edit')}}" class="form form-horizontal" id="form-spway-edit">

其他有用功能:

$uri = $request->path();
$url = $request->url();
$url = $request->fullUrl();
asset()
app_path();
// ...

https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php

另一种可能:{{URL::route('index')}}

要获得应用程序的url,你可以使用:

Config::get('app.url')