确认和取消按钮 Laravel Sweet Alert

Confirm and Cancel Button Laravel Sweet Alert

早上好:

我正在尝试在 Laravel 中使用插件 Sweet Alert。 我的问题是,我不知道如何在控制器中放置带有取消按钮和确认按钮的警报。 看了文档,只找到这句话:

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

此外,我正在尝试:

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>';

但它不起作用。

如何在显示取消按钮和确认按钮的控制器中使用 Sweet Alert?

谢谢

如果您正在使用 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

控制器

你的控制器应该是这样的

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

    return to whatever view    
   //return redirect::home();
}

查看

在你从 store 方法重定向的视图中,你应该像 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:: 我还没有使用甜蜜警报,但这个 repo 很酷!关于甜蜜提醒,你想知道的都有!