The modal appears and then it is removed

2

I'm doing my app in Laravel 5.1 and I get the following problem, I'm trying to delete a user, by pressing the delete button I display a modal as a "warning" to know if I want to delete that user and resolved that when I click the button to remove the modal unfolds, shows me the content of the modal and then removes. It appears as if the modal was active but nothing is seen.

It looks like this.

I want to clarify that this error only happens to me when the delete button sends it with a href="{{route('admin.usuario.destroy', $usuario->id) }}" If the field has that the modal is removed, if the href is empty, the modal simply appears.

This is where I have my delete and edit buttons, which is my index.blade.php

@extends('layouts.admin')

@section('title','Listado de Usuarios')
@section('contenido')
    @include('alertas.mensajeCreado')
    @include('admin.usuario.modal')

    <!--Metodo para hacer la busqueda en los usuarios-->
    {!!Form::open(['route'=>'admin.usuario.index','method'=>'GET', 'class'=>'navbar-form navbar-left pull-right','role'=>'search'])!!}
    <div class="form-group">
        {!!Form::text('name',null,['class'=>'form-control','placeholder'=>'Buscar'])!!}
    </div>
    <button type="submit" class="btn btn-default"><i class="fa fa-search" aria-hidden="true"></i>Buscar</button>
    {!!Form::close()!!}
    <!--FIN DEL METODO-->

    <table class="table table-striped table-bordered table-hover table-responsive">
        <thead>
            <th class="active">Nombre</th>
            <th class="active">Correo</th>
            <th class="active">Tipo de Usuario</th>
            <th class="active">Operacion</th>
        </thead>
        @foreach($usuarios as $usuario)
            <tbody>
                <td class="success">{{$usuario->name}}</td>
                <td class="success">{{$usuario->email}}</td>
                <td class="success">{{$usuario->tipoUsuario}}</td>
                <td class="success">
                    <div class="btn-group btn-group-lg">
                        <a href="{{route('admin.usuario.edit', $usuario->id) }}" class="btn btn-success" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> </a>
                        <a href="{{route('admin.usuario.destroy', $usuario->id) }}" class="btn btn-danger" role="button" data-toggle="modal" data-target="#myModal"><i class="fa fa-trash" aria-hidden="true"></i> </a>
                    </div>
                </td>
            </tbody>
        @endforeach
    </table>
    <div align="center">
        {!! $usuarios->appends(array('search'=> Input::get('search')))->render() !!}

    </div>

@endsection

In that case if I press edit, it sends me to my window to edit and loads the user I want to edit, that's it without problem. My problem lies mainly in that when pressing delete the modal is shown and it is removed and remains as shown in the image. It is only shown once then you press it and it gets like this.

My code modal.blade.php

<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">¿Seguro que desea eliminar?</h4>
        </div>
        <div class="modal-body">

                <div class="form-group">
                    <label >Nombre:</label>
                    <input type="text" name="name" class="form-control" disabled>

                </div>
                <div class="form-group">
                    <label >Email:</label>
                    <input type="email" name="email" class="form-control" disabled>

                </div>

        </div>
        <div class="modal-footer">
            {!!Form::open(['route'=>['admin.usuario.destroy'],'method'=>'DELETE'])!!}
            <center>{!!Form::submit('Si',['class'=>'btn btn-danger'])!!}
            <a class="btn btn-success" onclick="return cerrarPopup();">No</a></center>
            {!!Form::close()!!}
            @section('scriptModal')
                {!!Html::script('js/modal.js')!!}
            @endsection
        </div>
    </div>
</div>

Modal.js

function cerrarPopup() {
    $("#myModal").modal('toggle');
    $('#myModal').fadeOut();
}

My method destroy within the controller

public function destroy($id)
{
    $user = User::find($id);  
    $user->fill($request->all());
}
    
asked by Luis Morales 28.09.2016 в 09:03
source

0 answers