简体   繁体   English

在Laravel中生成URL

[英]Generating url in laravel

I have a problem with url in Laravel 我在Laravel中遇到网址问题

<td> Website: <a href="{{url($data[0]->internet)}}" target="_blank">{{$data[0]->internet}}</a></td>

where internet is some website name, for example www.foo.com internet是一些网站名称,例如www.foo.com

The problem is that output URL is http://localhost/www.foo.com instead of http://www.foo.com 问题在于输出URL是http://localhost/www.foo.com而不是http://www.foo.com

将目标属性target="blank"更改为target="_blank"

尝试这种方式:

<a href="{!! $data[0]->internet !!}" target="_blank">{{$data[0]->internet}}</a>

Change your html to 将您的html更改为

<a href="{{ $data[0]->internet }}" target="_blank">{{$data[0]->internet}}</a>

As stated in the Laravel documentation: https://laravel.com/docs/5.7/urls 如Laravel文档中所述: https ://laravel.com/docs/5.7/urls

The url helper may be used to generate arbitrary URLs for your application. url帮助程序可用于为您的应用程序生成任意URL。 The generated URL will automatically use the scheme (HTTP or HTTPS) and host from the current request 生成的URL将自动使用方案(HTTP或HTTPS)并从当前请求中托管

$post = App\Post::find(1);

echo url("/posts/{$post->id}");

// http://example.com/posts/1

In your case you won't need the url helper function. 在您的情况下,您将不需要url帮助器功能。


Also make use of the http or https protocol in this format: http://www.foo.com or https://www.foo.com to make an absolute url instead of a relative one. 还可以使用以下格式的http或https协议: http : //www.foo.comhttps://www.foo.com来创建绝对URL而不是相对URL。

If your variable internet is some website name, for example www.foo.com and you need to link this URl in anchor tag you dont need to call this variable inside url() function you can simply use that variable to link the url in anchor tag. 如果您的变量Internet是某个网站名称,例如www.foo.com,并且您需要在定位标记中链接此URl,则无需在url()函数中调用此变量,您只需使用该变量即可在定位器中链接该网址标签。

If you want to get the base URL of your site then you can use url() fucntion which return base url of your website. 如果要获取网站的基本URL,则可以使用url()功能,该函数返回网站的基本URL。

Just replace below line with your code 只需将下面的代码替换为您的代码

<td> 
Website: 
<a href="{{$data[0]->internet}}" target="_blank">{{$data[0]->internet}}</a>
</td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM