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

echo base_url();

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


当前回答

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

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

其他回答

Laravel提供了很多帮助函数,根据你的需求,你可以简单地

使用Laravel Helpers的url()函数

但在Laravel 5.2中,你必须使用url('/')

下面是Laravel所有其他辅助函数的列表

我还使用了base_path()函数,它为我工作。

这样的:

echo url('/');

这:

echo asset('/');

在我的情况下,两者都显示了主页url:)

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

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

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

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

request()->getSchemeAndHttpHost();