The button doesn't do anything at all. It works if I make a form with submit inside each <td tag, but obviously I don't wanna do that since then you can't read all the values. I just wanna have 1 submit button, for some reason that breaks it. facepalm
Came across few similar topics but none of them quite had any solution I was looking for.
html:
<table class="table table-hover">
@foreach ($query as $x)
<tr class="table-dark">
<form method="post" action="{{ action('Controller@admin_changeinfo') }}" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<th scope="row">User#{{$x->user_id}}</th>
<td>{{$x->name}}</td>
<td>
<input name="target" type="hidden" value="{{$x->user_id}}"/>
<input name="name" type="hidden" value="{{$x->name}}"/>
<input name="email" type="text" class="form-control"
id="admin_place_em" value="{{$x->email}}" placeholder="{{$x->email}}">
</td>
<td>
<select name="role" class="custom-select" id="admin_role_change">
<option selected="" value={{$x->role}}>{{$role_ar[$x->role]}}</option>
<option value="1" class="admin_role_opt">Value 1</option>
<option value="2" class="admin_role_opt">Value 2</option>
<option value="0" class="admin_role_opt">Value 0</option>
<option value="3" class="admin_role_opt">Value 3</option>
</select>
</td>
<td>
<input name="" type="submit" value="Update" href="/admin" class="btn btn-default">
</td>
</form>
</tr>
@endforeach
{{$query->links()}}
</table>
And here is the route if that's any help:
Route::post('/admin','Controller@admin_changeinfo');
--
EDIT: Apparently, you can't have a Form inside a table .
Solution: Put the whole table inside the form. Create a button with an unique value, make the other fields unique as well:
<button name="submit" type="submit" value={{$x->user_id}} href="/admin" class="btn btn-default">
Update
</button>
In your controller:
$pressed = $request->submit;
$this -> validate($request, [
'email'.$pressed => 'required',
'role'.$pressed => 'required|in:1,2,3,0'
]);
$name = $request -> input('name'. $pressed);
$target = $request -> input('target'. $pressed);
return 'submit called: '.$name.' '.$target;
Fixed version:
<form method="post" action="{{ action('Controller@admin_changeinfo') }}" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<table class="table table-hover">
@foreach ($query as $x)
<tr class="table-dark">
<th scope="row">User#{{$x->user_id}}</th>
<td>{{$x->name}}</td>
<td>
<input name="target{{$x->user_id}}" type="hidden" value="{{$x->user_id}}"/>
<input name="name{{$x->user_id}}" type="hidden" value="{{$x->name}}"/>
<input name="email{{$x->user_id}}" type="text" class="form-control"
id="admin_place_em" value="{{$x->email}}" placeholder="{{$x->email}}"/>
</td>
<td>
<select name="role{{$x->user_id}}" class="custom-select" id="admin_role_change">
<option selected="" value={{$x->role}}>{{$role_ar[$x->role]}}</option>
<option value="1" class="admin_role_opt">Value 1</option>
<option value="2" class="admin_role_opt">Value 2</option>
<option value="0" class="admin_role_opt">Value 0</option>
<option value="3" class="admin_role_opt">Value 3</option>
</select>
</td>
<td>
<button name="submit" type="submit" value={{$x->user_id}} href="/admin" class="btn btn-default">
Update
</button>
</td>
</tr>
@endforeach
{{$query->links()}}
</table>
</form>