【问题标题】:Confirm and Cancel Button Laravel Sweet Alert确认和取消按钮 Laravel Sweet Alert
【发布时间】:2017-10-01 07:46:43
【问题描述】:

早安:

我正在尝试在 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?

谢谢

【问题讨论】:

  • 嗨,你在使用这个 repo 吗? github.com/uxweb/sweet-alert
  • 看起来他正在使用它。我个人认为图书馆创造了比必要更多的工作。像这样简单的东西; swal({ title: 'Are you sure?', text: '该产品将被添加。', type: 'info', showCancelButton: true, confirmButtonText: '是的,导入它!', cancelButtonText: '否,取消' }) 应该管用。只需包含 limonte.github.io/sweetalert2 脚本即可。
  • 在你的 HTML 中包含 sweetalert2 脚本之后,你有没有在 Laravel 之外尝试过这个?可能没有包含脚本。
  • 看来他正试图从控制器本身调用,因为他正在使用 echo 来实现这一点..
  • 感谢您的回答。是的,我在 Laravel 5.4 中使用来自 Github 的 Sweet-Alert 我无法显示带有 de 代码的确认按钮给我文档。只能显示关闭按钮:->persistent('Close');我读到了一种在控制器中使用“echo”的方法。但是,我正在测试并且无法正常工作。

标签: php laravel sweetalert


【解决方案1】:

如果您使用的是this repo,那么我坚持要您仔细阅读文档,因为它给出了如何使用适当的 sn-ps 生成警报您基本上是在寻找 this

来自回购本身的片段

控制器

你的控制器应该是这样的

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 很酷!它有你想知道的关于甜蜜警报的一切!

【讨论】:

  • 嗨。我需要在控制器中显示一个按钮确认和取消。当一个条件成功并且之前保存。 ->持久('关闭');这对我来说还不够。
  • 但是你可以使用 showConfirmButton 你试过了吗??
  • 抱歉耽搁了。你的意思是我可以使用 ->persistent('showConfirmButton ') ??
  • 好的,谢谢!但是,我没有在文档中看到它。不管怎样,我会试试看的。
  • 我已从 docs bro 中添加了此代码,如果您发现任何困难,我们将尝试解决,如果您得到您想要的,请尝试解决这个问题,谢谢 :)跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多