Changing the content of Modal Laravel 5.1

Asked

Viewed 607 times

2

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

But it’s only bringing from the first user I click.

Follows 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'));
}
  • You are doing via ajax ? You’re making a mistake ?

  • I’m not using ajax I thought with Laravel directly by Controller would work

  • So how are you activating without refresh? You could post the full code ?

  • It would not be without refresh when click on the grid link give a get on Route and access the Controller show($id) and it returns to view editSchools that would be Modal

  • I’ll test a moment.

  • All the users you click to edit load the same data into the modal, is that it? As if you had always clicked on the same user?

Show 1 more comment

1 answer

1

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

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 presentation

@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 to know if there are any users on that route.
I ask if this set any user, positive case I show my modal with the information.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.