Laravel 5.1 pass data from view to modal

亡梦爱人 提交于 2019-11-29 12:52:56
Saiyan Prince

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

<a
    href="#"
    data-target="yourModalId"
    data-toggle="modal"
    data-email="{{ $user->email }}"
    data-username="{{ $user->username }}"
 >
     Edit
</a>

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..

blade include() function getting array as second parameter:

@include(('user.edit', ['user' => $user])

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!