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

echo base_url();

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


当前回答

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

其他回答

您也可以使用URL::to('/')在Laravel中显示图像。请参阅以下内容:

<img src="{{URL::to('/')}}/images/{{ $post->image }}" height="100" weight="100"> 

假设,您的图像存储在“public/images”下。

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

Config::get('app.url')

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

有多种方法:

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

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

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