Laravel刀片模板,URL :: to内的foreach变量? [英] Laravel blade templates, foreach variable inside URL::to?

查看:66
本文介绍了Laravel刀片模板,URL :: to内的foreach变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建帖子的基本列表视图,并且需要指向编辑"页面的链接.

I'm creating a basic list view of posts, and need a link to the 'edit' page.

我使用的是Blade,我有一张桌子,上面有一个foreach循环,显示了每个帖子以及编辑/删除按钮.

I'm using blade, and what I have is a table, with a foreach loop, showing each post along with edit/delete buttons.

我想做的是使用Blade的URL :: to指向编辑和删除页面的链接,以确保链接一致.

What I wanted to do is use blade's URL::to for the links to the edit and delete pages, to ensure consistant links.

我尝试使用的代码(记住这是在foreach循环内,因此$ post-> id var)是这样的:

The code I've tried using (remember this is inside a foreach loop hence the $post->id var) is this:

<a href="{{ URL::to('admin/posts/edit/$post->id') }}" class="btn btn-mini btn-primary">Edit Post</a>

但是,这不起作用.我也尝试过

However this does not work. I've also tried

<a href="{{ URL::to('admin/posts/edit/<?php echo $post->id; ?>') }}" class="btn btn-mini btn-primary">Edit Post</a>

这也不起作用.

我没有收到任何错误,链接字面意思是:

I dont get any error, the link literally ends up being:

http://domain.dev/admin/posts/$post->id

有什么办法解决这个问题?

Is there any way of working around this?

推荐答案

我认为问题在于,您正在使用带有单个'的字符串中的php变量($ post).在这种情况下,它仅输出变量的名称.试试这个:

I think the problem is that you are using php variable ($post) within a string with a single '. In this case it just outputs the name of the variable. Try this:

<a href="{{ URL::to('admin/posts/edit/' . $post->id) }}" class="btn btn-mini btn-primary">Edit Post</a>

希望这会有所帮助. 弗拉德

Hope this helps. Vlad

这篇关于Laravel刀片模板,URL :: to内的foreach变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆