I'm creating a basic list view of posts, and need a link to the 'edit' page.
I'm using blade, and what I have is a table, with a foreach loop, showing each post along with edit/delete buttons.
What I wanted to do is use blade's URL::to for the links to the edit and delete pages, to ensure consistant links.
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>
which also doesnt work.
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?
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:Hope this helps. Vlad
vlad has already given the right answer to your question but be aware that you can also directly link to your controller action via
URL::action
:I think this will work
The
{{ }}
are equal to<?php echo ;?>
if you put single
'
<?php echo '$hello' ?>
= $hellobut if you put double
' (")
-><?php "$hello" ;?>
= Hello World (just one example)You need to write something like
{{ URL::to("admin/posts/edit/$post->id") }}
Also you may use
route()
helper to generate url by name of route. For example, definition of route:Code in your view:
Had an issue with this in Laravel 5 so thought Id pop it in even if the question is old. Resolved my issue using
{{ URL::to('/box').'/'.$box->id }}
or
{{ url('/box').'/'.$box->id }}