I am trying to pass a variable inside the action attribute as shown
<form method="POST" action="{{url('/posts/{$post->id}/comments')}}">
The URL after submitting the form is this;
http://localhost/Laravel/public/posts/%7B$post-%3Eid%7D/comments
- 3Eid represents '->'
while the value of $post->id is supposed to be 30 in my case.
Can you please tell me the way to pass the value of $post->id?
Script47
14.6k4 gold badges49 silver badges69 bronze badges
2 Answers 2
replace ' with ":
<form method="POST" action='{{url("/posts/{$post->id}/comments")}}'>
answered Jun 14, 2018 at 14:32
Metalik
9431 gold badge10 silver badges30 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Change ' too "
so this
<form method="POST" action="{{url('/posts/{$post->id}/comments')}}">
becomes
<form method="POST" action='{{url("/posts/{$post->id}/comments")}}'>
Only if you use the double quotes you can echo with {}
Comments
default
input type="hidden".