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:
<a href="{{ URL::to('admin/posts/edit/' . $post->id) }}" class="btn btn-mini btn-primary">Edit Post</a>
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
:
<a href="{{ URL::action('Admin\PostsController@edit', $post->id) }}">Edit</a>
The {{ }}
are equal to <?php echo ;?>
if you put single '
<?php echo '$hello' ?>
= $hello
but if you put double ' (")
-> <?php "$hello" ;?>
= Hello World (just one example)
You need to write something like {{ URL::to("admin/posts/edit/$post->id") }}
I think this will work
<a href="{{ url('test/'.$post->id.'/view') }}"></a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With