Laravel 5.1 pass data from view to modal

后端 未结 2 608
花落未央
花落未央 2020-12-18 15:09

How can I pass data from blade view to modal dialog : For example : I pass $user from controller to view :

 $user = User::findOrFail($id);
 return view(\'us         


        
2条回答
  •  醉酒成梦
    2020-12-18 15:37

    Try out this way. I am using a tag, but the solution should work for you as well with button.

    
         Edit
    
    

    jQuery code:

    $('#yourModalId').on('show', function(e) {
        var link     = e.relatedTarget(),
            modal    = $(this),
            username = link.data("username"),
            email    = link.data("email");
    
        modal.find("#email").val(email);
        modal.find("#username").val(username);
    });
    

    Create the input fields inside the modal window with the id that are passed in find method.

    That will put the values passed in the input fields inside modal window..

提交回复
热议问题