Form which uses POST method:
<div>
<form action="{{ route('post.store') }}" method="POST">
<input type="text" name="name">
<input type="text" name="text">
<button type="submit">Submit</button>
</form>
@foreach ($comments as $comment)
{{ $comment->text }}
<a href="#">Reply</a>
@endforeach
</div>
Array of $comments
is being returned when the view itself is returned.
Basically, I am intrested if there is a way to append $comment->id
to the data that will be sent to server on Submit
button click using Laravel Blade or AlpineJS, but without creating any additional functions between <script>
tags? I mean, is it possible to do something like this: <a href="#" @click.prevent="formData.append('parent_comment_id', {{ $comment->id }})">Reply</a>
?
EDIT:
I expressed myself wrongly. I don't want to append new id
every time Reply
is clicked, but to overwrite corresponding property in data which is going to be sent to server when Submit
button is clicked with the $comment->id
for which Reply
was clicked for.
question from:
https://stackoverflow.com/questions/65871205/append-data-to-form-using-through-dom 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…