0
I have a table where I list all the users I have in the database and I have a td
where are the actions for them that contain two buttons load balance and change the password at this time I am trying to do and change the password i by clicking the change password button opens a model
which has two new password fields and reintroduce password have already ajax done and working together with the controller
of the Language that updates the database the problem and that I have two users and when I try to update the password of the user 2 it changes the password of the user 1 I do not know what the problem count on your help
Code of the User List
@extends('admin.index')
@section('title', 'Jogadores')
@section('content')
<div class="row">
<div class="col-lg-12">
<div class="content-box">
<div class="head info-bg clearfix">
<h5 class="content-title pull-left">Listagem de Jogadores</h5>
<div class="functions-btns pull-right">
<a class="refresh-btn" href="#"><i class="zmdi zmdi-refresh"></i></a>
<a class="fullscreen-btn" href="#"><i class="zmdi zmdi-fullscreen"></i></a>
<a class="close-btn" href="#"><i class="zmdi zmdi-close"></i></a>
</div>
</div>
<div class="content">
<div class="table-responsive alt-table">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="table-check">
ID do Jogador
</th>
<th>Nome do Jogador</th>
<th>Data do Registo</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
@foreach($players as $listar_players)
<tr>
<td class="table-check">
{{ $listar_players->id }}
</td>
<td class="table-check">
{{ $listar_players->username }}
</td>
<td class="table-check">
{{ $listar_players->created_at }}
</td>
<td class="table-check">
<div class="btn-group">
<button type="button" data-toggle="modal" data-target="#modal-add-credito" class="btn btn-success"><i class="fa fa-usd" aria-hidden="true"></i></button>
<button type="button" data-toggle="modal" data-target="#modal-update-senha" class="btn btn-success"><i class="fa fa-key" aria-hidden="true"></i></button>
</div>
<div class="modal fade" id="modal-update-senha" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Mudar Password</h4>
</div>
<div class="modal-body">
<form action="alterarPassword" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<div class="col-sm-12">
<input type="password" class="form-control" id="password" name="password" placeholder="Nova Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="password" class="form-control" id="conf_password" name="conf_password" placeholder="Reintroduza nova password">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="btn-update-pass-{{ $listar_players->id }}" class="btn btn-lg btn-info m-b-5">Guardar</button>
<button type="button" class="btn btn-lg btn-default m-b-5" data-dismiss="modal">Cancelar</button>
</div>
</div>
</div>
</div>
<script>
$(document.body).on('click', '#btn-update-pass-{{ $listar_players->id }}', function(e) {
var password = $("#password").val();
var conf_password = $("#conf_password").val();
if(password === '' || conf_password === ''){
toastr.error('Preencha os campos obrigatórios!');
}else if(password != conf_password){
toastr.error('Password não coincide');
}else{
e.preventDefault();
var id_jogador = "{{ $listar_players->id }}";
var password = $("input#password").val();
var dataString = 'id_jogador='+id_jogador+'&password='+password;
$.ajax({
type: "POST",
url: "alterarPassword",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: dataString,
cache: true
}).done(function( msg ) {
toastr.success('Dados guardados com sucesso!');
}).fail(function(data) {
toastr.error('Ocorreu um erro!');
});
}
});
</script>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
Controller
namespace App\Http\Controllers\admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Jogadores;
use DB;
use Auth;
use Redirect;
use Hash;
use Response;
use Illuminate\Support\Facades\Input;
class AlterarSenhaJogadoresController extends Controller{
public function update_senha_jogador (Request $request){
$id_jogador = $request->input( 'id_jogador' );
$password = Hash::make($request->input( 'password' ));
$update_senha_jogador = DB::table('players')->where('id', '=', $id_jogador)->update(array('passwd' => $password));
}
}
I did it all like I said in the question but it still does the same as getting id 1 when I try to change id 2
– César Sousa
@Césarsousa when generating the page press Ctrl+U, it will open the view-source, then copy and paste in Pastebin and send me.
– Guilherme Nascimento
Don’t let me create in Pastebin says that Possible Spam Detected
– César Sousa
I already got you here at this link http://pasted.co/400e7d50
– César Sousa
I left the link already saw ?
– César Sousa
@Césarsousa to try to discover the origin of the problem
– Guilherme Nascimento
OK thanks so much for the help
– César Sousa
Found something, my friend ?
– César Sousa