Changing the content of Modal Laravel 5.1

2

I have a Grid with the edit button when I click on it it accesses the Controller and brings the data of a certain user into a Modal.

But it's just bringing in the first user I click.

Follow the code:

Grid Link

<a href=".../show/{{$valor->id}}" data-target="#editModal" data-toggle="modal">Editar</a></td>

Route

Route::get('/show/{id}', '...\EscolaController@show');

Controller

public function show($id)
{


    $escola = $this->escola->find($id);


    return view('....editEscolas', compact('escola'));
}
    
asked by anonymous 01.08.2016 / 21:52

1 answer

1

I just made a very simplistic example and it worked here. See if you can help:

Route

Route::get('see/{id}', 'Adm\UsuarioController@show');

Controller

$data['usuario'] = User::find($id);

Request button

@foreach($usuarios as $key => $value) <!-- Aqui eu tenho todos os meus usuários -->
<a class="btn btn-default btn-xs btn-block" href='{{url("see/$value->id")}}'>
    See
</a>
@endforeach

Modal submission

@if(isset($usuario))
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">{{$usuario->name}}</h4>
          </div>
          <div class="modal-body">
            {{$usuario->email}}
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript">
        $(window).load(function(){
            $('#myModal').modal('show');
        });
    </script>
@endif

See the main thing is you know if there is any user on that route. I ask if this set is a user, if so I show my modal with the information.

I hope I have helped.

    
01.08.2016 / 22:22