【问题标题】:laravel : how to set session with opening modallaravel:如何使用打开模式设置会话
【发布时间】:2019-08-10 12:42:28
【问题描述】:

我有 2 个按钮用于 2 个模态。在下面的代码中:

<div>
    <h3>1 month</h3>
    <button type="button" class="pay-btn-1" data-toggle="modal" data-target="#modal1">Pay this featur</button>
</div>

<div>
    <h3>2 month</h3>
    <button type="button" class="pay-btn-2" data-toggle="modal" data-target="#modal2">Pay this featur</button>
</div>

我在页脚中插入了 2 个模态:

<------ Modal 1------->
    <div id="modal1" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <?php
            Session::flush('month');
            Session::put('month', 1);
            ?>
            <!-- Modal content-->
            <div class="modal-content">
                <form action="{{ route('panel.vip.payment') }}" method="post">
                    @csrf
                    <input type="hidden" value="1" name="plan">
                    <div>
                        <button type="submit">pay</button>
                    </div>
                </form>

                <button type="button" data-dismiss="modal">close</button>
            </div>

        </div>
    </div>

<------ Modal 2------->
    <div id="modal2" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <?php
            Session::flush('month');
            Session::put('month', 2);
            ?>
            <!-- Modal content-->
            <div class="modal-content">
                <form action="{{ route('panel.vip.payment') }}" method="post">
                    @csrf
                    <input type="hidden" value="2" name="plan">
                    <div>
                        <button type="submit">pay</button>
                    </div>
                </form>

                <button type="button" data-dismiss="modal">close</button>
            </div>

        </div>
    </div>

我想在点击任何支付按钮时清除month 会话,然后在month 会话中设置该按钮的值(1 或 2)

我该怎么做?

谢谢。

【问题讨论】:

  • 点击按钮后会发生什么?
  • @vivek_23 ,模式正在打开。我想通过打开每个模式来设置自定义会话。
  • 然后发出ajax请求并更改会话值
  • @vivek_23 ,我该怎么做?
  • 试试 JQuery ajax api.jquery.com/jquery.ajax 。当有人点击按钮时,向控制器发出请求并更改会话。

标签: php laravel session bootstrap-modal


【解决方案1】:

按钮代码:

<div>
    <h3>1 month</h3>
    <button type="button" class="pay-btn-1" data-toggle="modal" data-target="#modal1">Pay this featur</button>
</div>

模式代码:

<------ Modal 1------->
    <div id="modal1" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
                <form action="{{ route('payment') }}" method="post">
                    @csrf
                    <input type="hidden" value="1" name="plan">
                    <div>
                        <button type="submit">pay</button>
                    </div>
                </form>

                <button type="button" data-dismiss="modal">close</button>
            </div>

        </div>
    </div>

单击按钮并在服务器端删除会话时将 ajax 发送到 PHP。

见下面的代码:

$('.pay-btn-1').click(function (e) {
                e.preventDefault();
                $.ajax({
                    type   : 'post',
                    url    : '/clear-session',
                    data   : {_token: "{{ csrf_token() }}"},
                    success: function (data) {
                        //
                    }
                });
            });

现在在controller on clearSession 方法中:

public function clearSession(Request $request)
    {

        $request->session()->forget('Vip');

        return response()->json('ok', 200);

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-06
    • 2010-12-23
    • 2017-06-14
    • 2021-09-10
    • 2020-06-26
    • 2018-03-18
    • 2021-07-15
    • 2014-11-22
    相关资源
    最近更新 更多