【发布时间】:2022-02-11 03:30:44
【问题描述】:
使用 POST 方法的表单:
<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>
在返回视图本身时,将返回 $comments 数组。
基本上,如果有一种方法可以将$comment->id 附加到将使用 Laravel Blade 或 AlpineJS 单击Submit 按钮时发送到服务器的数据,但不会在<script> 标记之间创建任何附加功能,我很感兴趣?我的意思是,是否可以这样做:<a href="#" @click.prevent="formData.append('parent_comment_id', {{ $comment->id }})">Reply</a>?
编辑:
我错误地表达了自己。我不想每次单击Reply 时都附加新的id,而是要在使用$comment->id 的@987654331 单击Submit 按钮时覆盖将要发送到服务器的数据中的相应属性@ 被点击了。
【问题讨论】: