dimanche 1 novembre 2015

Update method laravel using modal box

My update method is working unfortunately it always updates the wrong data in this case it always updates the last data in my db list. I believe this occurs because my modal box directs to $user->id which always points to the last id as I have a for loop used at the top, is there a ways I could do to point it to the selected id instead?

view.blade.php

<div class="well col-xs-9 col-sm-9 col-md-9 col-lg-9 col-xs-offset-1 col-sm-offset-1 col-md-offset-1 col-lg-offset-1">
    @foreach ($users as $user)
    <div class="row user-row">
    <!--div class="col-xs-3 col-sm-2 col-md-1 col-lg-1">
        <img class="img-circle"
             src="http://ift.tt/1LL8Rgw"
             alt="User Pic">
         </div-->
         <div class="col-xs-2 col-sm-3 col-md-4 col-lg-4">
            <h5 style="font-weight: bold">{{ $user->name }}</h5>
         </div>
         <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 dropdown-user" data-for=".{{ $user->id }}">
          <h5 class="glyphicon glyphicon-chevron-down text-muted pull-right">&nbsp;</h5>
      </div>
  </div>
  <div class="row user-infos {{ $user->id }}">
      <div class="col-xs-12 col-sm-12 col-md-10 col-lg-10 col-xs-offset-0 col-sm-offset-0 col-md-offset-1 col-lg-offset-1">
         <div class="panel panel-info">
            <div class="panel-heading">
               <h2 class="panel-title">User Information</h2>
           </div>
           <div class="panel-body">
               <div class="row">
                <div class=" col-md-10 col-lg-10 hidden-xs hidden-sm">
                   <div class="col-xs-5">User level:</div><div class="col-xs-5"> {{ $user->role->role_description }}</div>
                   <div class="col-xs-5">Email:</div> <div class="col-xs-5"> {{ $user->email }}</div>
                   <div class="col-xs-5">Phone number: </div> <div class="col-xs-5"> {{ $user->mobile }} </div>
                   <div class="col-xs-5">Office extension: </div> <div class="col-xs-5"> [ TO IMPLEMENT ]</div>
               </div>
           </div>
       </div>
       <div class="panel-footer">
          <button class="btn btn-sm btn-warning" type="button"
          data-toggle="modal" data-target="#form">Edit&nbsp;<i class="glyphicon glyphicon-edit"></i></button>
          <span class="pull-right">
             <button class="btn btn-sm btn-danger" type="button">Inactive&nbsp;<i class="glyphicon glyphicon-remove"></i></button>
         </span>
     </div>
 </div>
</div>
</div> 
@endforeach             
</div> 

@if(Session::has('flash_message'))
    <div class="alert alert-success col-xs-9 col-sm-9 col-md-9 col-lg-9 col-xs-offset-1 col-sm-offset-1 col-md-offset-1 col-lg-offset-1">
        {{ Session::get('flash_message') }}
    </div>
@endif

<div class="col-sm-offset-1 col-sm-2">

    <!-- Trigger the modal with a button -->
    <button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#form">Register New User</button>

    <!-- Modal -->
    <div id="form" class="modal fade" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
               <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">User Information</h4>
              </div>
              <div class="modal-body">
                  <form class="form-horizontal" role="form" method="POST" action="/manage_accounts/{{ $user->id }}" novalidate>
                   <input type="hidden" name="_method" value="PUT">
                   <input type="hidden" name="_token" value="{{ csrf_token() }}">
                   <div class="form-group">
                    <label class="control-label col-sm-3" for="name">Username:</label>
                    <div class="col-sm-5 @if ($errors->has('name')) has-error @endif"> 
                       <input type="text" class="form-control" type="hidden" id="name" name="name" placeholder="Enter username">
                       @if ($errors->has('name')) <p class="help-block">{{ $errors->first('name') }}</p> @endif
                   </div>
               </div>

...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire