user editor, only edit the first record

I am working in a user editor, I have a problem, just edit the first record.

when I want to edit another different user it sends me data only from the first one

  public function usuarios(Request $request){
$data = [
'category_name' => 'apps',
'page_name' => 'contacts',
'has_scrollspy' => 0,
'scrollspy_offset' => '',
];
$usuarios = User::All();

// $pageName = 'contacts';
return view('usuarios',compact('usuarios'))->with($data);
}
public function userupdate(Request $request){


foreach($request->service as $key=>$value){

$nuevoIngreso = User::find($value['id']);
if($nuevoIngreso){
$nuevoIngreso->name = $value['name'];
$nuevoIngreso->email = $value['email'];
$nuevoIngreso->telefono = $value['telefono'];

$nuevoIngreso->tipo = $value['tipo'];
$nuevoIngreso->save();
}
}

// $pageName = 'contacts';
return redirect('usuarios')->with('mensaje', 'Ficha Actualizada.');
}

Blade.php

    @extends('layouts.app')



@section('content')
<div id="tableCheckbox" class="col-lg-12 col-12 layout-spacing">
<div class="statbox widget box box-shadow">
<div class="widget-header">
<div class="row">
<div class="col-xl-12 col-md-12 col-sm-12 col-12 mt-3 text-center">
<h2>Usuarios</h2>
</div>
</div>

</div>
<div class="widget-content widget-content-area">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped table-checkable table-highlight-head mb-4">
<thead>
<tr>
<th class="checkbox-column">
<label class="new-control new-checkbox checkbox-primary" style="height: 18px; margin: 0 auto;">
<input type="checkbox" class="new-control-input todochkbox" id="todoAll">
<span class="new-control-indicator"></span>
</label>
</th>
<th class="">Nombre</th>
<th class="">Email</th>
<th class="">Telefono</th>
<th class="text-center">ACCIÓNES</th>
</tr>
</thead>
<tbody>
@foreach($usuarios as $key=>$users)
<tr>
<td class="checkbox-column">
<label class="new-control new-checkbox checkbox-primary" style="height: 18px; margin: 0 auto;">
<input type="checkbox" class="new-control-input todochkbox" id="todo-1">
<span class="new-control-indicator"></span>
</label>
</td>
<td>
<p class="mb-0"></p>
</td>
<td></td>
<td></td>

<td class="text-center">
<ul class="table-controls">
<li><a href="" data-placement="top" title="" data-original-title="Settings" data-toggle="modal" data-target="#registerModal"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-settings text-primary"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg></a> </li>
<li><a href="javascript:void(0);" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-2 text-success"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path></svg></a></li>
<li><a href="javascript:void(0);" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2 text-danger"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></a></li>
</ul>
</td>
</tr>
<div class="modal fade register-modal" id="registerModal" tabindex="-1" role="dialog" aria-labelledby="registerModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">

<div class="modal-header" id="registerModalLabel">
<h4 class="modal-title">Editar Usuario</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></button>
</div>
<div class="modal-body">

<form id="addContactModalTitle" class="mt-0" method="POST" action="">

@csrf
<input class="form-control" type="hidden" value="" name="service[][id]">
<div class="form-group">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
<input type="text" class="form-control mb-2" name="service[][name]" id="exampleInputUsername1" value="">
</div>
<div class="form-group">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-at-sign"><circle cx="12" cy="12" r="4"></circle><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"></path></svg>
<input type="email" class="form-control mb-2" name="service[][email]" id="exampleInputEmail2" value="">
</div>
<div class="form-group">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
<input type="phone" class="form-control mb-4" name="service[][telefono]" id="exampleInputPassword2" value="">
</div>
<div class="form-group">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
<input type="phone" class="form-control mb-4" name="service[][tipo]" id="exampleInputPassword2" value="">
</div>
<button type="submit" class="btn btn-primary mt-2 mb-2 btn-block">Actualizar</button>
</form>



</div>

</div>
</div>
</div>
@endforeach
</tbody>
</table>
</div>



</div>
</div>
</div>




@endsection

Routes:

 Route::get('usuarios','HomeController@usuarios');
Route::put('/usuarios', 'HomeController@userupdate' )->name('userupdate');

if necessary I can upload a screenshot of the problem to better understand.

When I click on edit the user ID = 2, or 3 sends me data from the user ID 1 only. in list it prints all the records, but in the form it only prints the first user



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3zrWBzd
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

BlueHost Web Hosting Review: Secrets Revealed for Shared Hosting

How to Create Treeview with Bootstrap and jQuery

Submit Form using jQuery AJAX and PHP without Page Refresh