我想在我的网站顶部显示我的商店位置,该位置可以由用户在laravel网站中单击并更改位置

问题描述

在我的购物站点中,我想显示我的商店位置,用户可以单击并选择附近的商店。我尝试使用JQuery的工作,但刷新时将其更改为认值。我想显示用户选择的存储位置,在会话销毁时不应更改它,而只需更改为认值即可

我的header_popup页面

    @foreach(session('locs') as $id => $details)

    <i class="fa fa-map-marker"></i> <button class="mystore" data-toggle="modal" data- 
     target="#myModal" id="mymodl" value="mymodl" data-id="">
     {{ $details['area']}}
      @endforeach
        <span id="status"></span>

    </button>
    <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

    <!-- Modal content-->
<div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Choose your nearby store</h4>
            <div class="modal-body header-pop-buton">
                @foreach($user as $store)


                <button class="mystore" data-id="{{ $store->id }}" value="{{ $store->area }}" >{{ 
    $store->area }}</button>


                @endforeach

            </div>
        </div>

我的脚本

  <script>
  $(".mystore").on('click',function (e) {
    e.preventDefault();

    var ele = $(this);

    $.ajax({
        url: '{{ url('header-loc') }}' + '/' + ele.attr("data-id"),method: "get",data: {_token: '{{ csrf_token() }}'},dataType: "json",success: function (response) {
            $("span#status").html('<div class="alert alert-success">'+response.msg+'</div>');
            $("#header-bar").html(response.data);

        }

       });
        $('#myModal').modal('hide');


        });
       </script>
   

在我的布局中,我使用@include(header_popup)

我的控制器

    public function headerloc(Request $request,$id)
    {


    $product = store::find($id);



    // if cart is empty then this the first product
    if ($locsd) {

        $locsd = [ $id => ["area" => $product->area]];

        session()->set('locs',$locsd);

        $htmlCart = view('header_popup')->render();

        return response()->json(['msg' => 'Product added to cart successfully!','data' => 
        $htmlCart]);

        //return redirect()->back()->with('success','Product added to cart successfully!');
        }



        }

提前谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)