1

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
asked Jun 14, 2018 at 14:27
2
  • Rather than passing it through the URL, I would pass it as a input type="hidden". Commented Jun 14, 2018 at 14:37
  • In the future please use the relevant tags and make your title clear. Commented Jun 14, 2018 at 14:38

2 Answers 2

4

replace ' with ": <form method="POST" action='{{url("/posts/{$post->id}/comments")}}'>

answered Jun 14, 2018 at 14:32
Sign up to request clarification or add additional context in comments.

Comments

1

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 {}

answered Jun 14, 2018 at 14:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.