Answer the question
In order to leave comments, you need to log in
How to get the value of a field that is displayed through foreach?
How to get only one specific value?
<table class="table">
@foreach ($files_info as $val)
<tr>
<th>{{$num++}}</th>
<td>{{$val['filename']}}</td>
<td><input value="{{$val['filename']}}" name="del_file" type="text" hidden><button type="button">удалить</button></td>
</tr>
@endforeach
</table>
public function del_file(Request $request)
{
$del_file_name = $request->input('del_file');
dd($del_file_name);
}
Answer the question
In order to leave comments, you need to log in
When asking a question, describe what you want to do.
In this case, you want to make a "delete" button for every row in the table, but you're doing it wrong.
You have one form for the entire table and many inputs with the same name del_file, so when processing you get only the last element.
You need a different form for each button
<table class="table">
@foreach ($files_info as $val)
<tr>
<th>{{$num++}}</th>
<td>{{$val['filename']}}</td>
<td>
<form action="" method="post">
<input value="{{$val['filename']}}" name="del_file" type="text" hidden><button type="button">удалить</button>
</form>
</td>
</tr>
@endforeach
</table>
You all have the same name input, so it's not surprising that you get only 1. There should be an array, probably, like:
Then get an array of values
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question