Confirm和取消按钮Laravel Sweet Alert

早上好:

我试图在Laravel中使用插件甜蜜警报。我的问题是,我不知道如何用取消按钮提醒并确认控制器中的确认按钮。阅读文档,我只发现了这句话:

Alert::warning('Are you sure?', 'message')->persistent('Close');

Also,我想:

echo '<script>swal({ title: "Are you sure?", text: "name is available, continue save?", type: "warning", showCancelButton: true, confirmButtonColor:"#DD6B55",  confirmButtonText: "Yes, delete it!",   closeOnConfirm: false }, function(){});</script>';

But it not working.

如何在我的控制器中使用Sweet警报显示取消按钮并确认按钮?

谢谢

hi are you using this repo? github.com/uxweb/sweet-alert.mr 金字塔
它看起来像是用那个。我个人认为图书馆比必要的工作创造了更多的工作。这么简单的东西; Swal({Title:'你确定吗?',文字:'将添加该产品。',键入:'info',showcancelbutton:true,confirectnbuttontext:'是,导入它!',cancelButtontext:'否,取消' }) 应该管用。只包括Limonte.github.io/sweetalert2.Scripts和那就是它。Comity
您在HTML中包含SweetAlert2脚本之后,您在Laravel之外尝试过这一点?也许脚本没有被包含在内。Comenity
it appears he is trying to call from controller itself as he is using echo for that..mr 金字塔
Thanks for your answers. Yes I am using Sweet-Alert from Github in Laravel 5.4 I can´t show a confir button with de code that give me the documentation. Only can show a Close Button: ->persistent('Close'); I read a way doing it with "echo" in the Controller. However, I am testing and not working.Miguel Herereros Cejas

回答 1

  1. 赞同 2

    如果您正在使用this repo then I insist you to read the docs thoroughly as it is given how generate alerts with proper snippets You are basically looking for this

    Snippet from the repo itself

    Controller.

    Your controller should look like this

    public function yourfunction()
    {
        Alert::warning('Are you sure?', 'message')->persistent('Close');
    
        return to whatever view    
       //return redirect::home();
    }
    

    从商店方法中重定向的视图中,您应该在repo中提供的东西

    @if (Session::has('sweet_alert.alert'))
        <script>
            swal({
                text: "{!! Session::get('sweet_alert.text') !!}",
                title: "{!! Session::get('sweet_alert.title') !!}",
                timer: {!! Session::get('sweet_alert.timer') !!},
                type: "{!! Session::get('sweet_alert.type') !!}",
                showConfirmButton: "{!! Session::get('sweet_alert.showConfirmButton') !!}",
                confirmButtonText: "{!! Session::get('sweet_alert.confirmButtonText') !!}",
                confirmButtonColor: "#AEDEF4"
    
                // more options
            });
        </script>
    @endif
    

    PS ::我还没有使用甜蜜的警报,但这个回购很酷!它拥有所有你想了解甜蜜警报的一切!

    mr 金字塔
    我需要在控制器中显示一个按钮并取消。当条件成功和之前保存。 - >持久('关闭');这对我来说还不够。Miguel Herereros Cejas
    but you can use showConfirmButton for that have you tried that??mr 金字塔
    延迟纪念品。你的意思是我可以使用 - >持久('showconfirmbutton')??Miguel Herereros Cejas
    OK,谢谢!但是,我没有在文档中看到它。无论如何,我会尝试一下。Miguel Herereros Cejas
    我从Docs兄弟添加了这个代码,试一试如果您发现任何困难,我们将尝试修复,同时如果您得到了您想要的那样,请接受关闭此问题的答案谢谢:)mr 金字塔