我们在@foreach
中有多个隐藏的输入,就像这样。
<form action="{{ route('parties.updateAndCreate', auth()->id()) }}" method="post">
@csrf
@method('PUT')
<input type="hidden" name="category_id" value="{{ $category->id }}">
@foreach($parties as $party)
@foreach($party->reals as $key => $real)
<input type="hidden" name="party_key" value="{{ $key }}">
@endforeach
@endforeach
我们必须单击“删除”
$(document).on('click', '.fa-trash', function() {
$("input[name='delete_parties[]']").val([$(this).attr('data-id')])
$(this).parent().parent().parent().remove();
});
当我点击它在控制器中发送的保存按钮时。
public function updateAndCreate (Request $request)
{
dd($request->post('delete_parties'));
我看到这个了。
^ array:6 [▼
"_token" => "ZpfR4IetOc9teRTFFT3ScnCCWkDnBc58T0mcmeLP"
"_method" => "PUT"
"category_id" => "3"
"party_key" => "0"
"parties" => array:1 [▼
3 => array:1 [▼
"real_person" => array:1 [▼
0 => array:2 [▼
"id" => "59"
"name" => "AA"
]
]
]
]
"contract_subject" => null
]
我如何将该$key删除为dd?
@foreach($parties as $party)
@foreach($party->reals as $key => $real)
<div class="col-lg-6 mb-3">
<fieldset class="border p-2">
<legend class="float-none w-auto p-2 pb-0 h6 fs-6 mb-0">real_person</legend>
<input type="hidden" name="parties[{{ $party->id }}][real_person][{{ $key }}][id]" value="{{ $real->id }}" />
<textarea name="parties[{{ $party->id }}][real_person][{{ $key }}][name]" id="real_person" class="form-control border-0" rows="10" aria-label="real_person">{{ $real->real_person }}</textarea>
<a class="cursor-pointer text-secondary"><i class="fa-solid fa-2x fa-trash"></i></a>
</fieldset>
</div>
@endforeach
@endforeach
发布于 2022-10-29 20:41:53
如果要将键重置为连续整数,则需要使用方法值()
https://stackoverflow.com/questions/74242761
复制相似问题