来自模态的Laravel尝试获取GET而不是POSt

问题描述 投票:0回答:1

模态从@foreach获取数据并显示它们。然后从表单中将输入的数据发布到下一个POST路由{{route('user.give')}}。但是,它一直尝试对另一个路由(恰好在其上方的路由)执行GET请求。请帮助,谢谢您的帮助

@section('content')
    @if (session('status'))
        <div class="alert alert-success" role="alert">
            {{ session('status') }}
        </div>
    @endif

    @if(count($orgs) > 0)
        @foreach($orgs as $org)
        <div class="card m-1 col-md-3 p-0">
            <img class="card-img-top" src="{{ asset('storage/'.$org->logo) }}" alt="{{ $org->name }} logo" />

            <div class="card-body">
                <span class="card-title"><strong><i class="fa fa-church"></i> {{ $org->name }}</strong></span>
                <div class="small"><i class="fa fa-exchange-alt"></i> {{ $org->alias }}</div>

                <p class="card-text"></p>
                <button class="btn btn-outline-primary rounded-0" data-toggle="modal" data-target="#exampleModalCenter">
                    <i class="fa fa-credit-card"></i>
                    Give
                </button>
                <a href="{{ route('user.oneclick.create', ['id' => $org->id]) }}" class="btn  btn-outline border-dark text-dark rounded-0"><i class="fa fa-cogs"></i></a>
            </div>
        </div>
        @endforeach
    @else
        <p>Sorry, there's no match for your search.</p>
    @endif

并且下面是模态。它实际上是上面代码的延续。模态实际上出现了,该问题仅在发布时发生

<!-- form modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalCenterTitle">Details</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <cite>You are about to give to {{ $org->name }}</cite>
      <!-- form -->
        <form method="POST" action="{{ route('user.give') }}">
            @csrf
            <input type="hidden" name="organisation_name" value="{{ $org->name }}">
            <input type="hidden" name="organisation_id" value="{{ $org->id }}">
            <input type="hidden" name="organisation_email" value="{{ $org->email }}">
            <input type="hidden" name="organisation_logo" value="{{ $org->logo }}">
            <div class="form-group">
                <label for="amount">Amount</label>
                <input type="number" class="form-control rounded-0" name="amount" aria-describedby="amount" placeholder="e.g 5000" required>
            </div>
            <div class="form-group">
                <label for="purpose">Purpose</label>
                <input type="text" class="form-control rounded-0" name="purpose" placeholder="e.g tithe">
            </div>
            <button type="submit" class="btn  btn-outline border-dark text-dark rounded-0" id="proceed">
                Proceed
            </button>
        </form>
      <!-- //form -->
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-outline border-dark text-dark rounded-0" data-dismiss="modal">Close</button>
        <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
      </div>
    </div>
  </div>
</div>
<!-- //form modal -->
@endsection
laravel post get routes modal-dialog
1个回答
0
投票

$org不是模态中想要的:它是循环中$org数组中循环中的最后一个$orgs,因为它不在@foreach循环中。

单击显示模态的按钮时,需要动态生成模态(通过javaScript或其他方式。)>

© www.soinside.com 2019 - 2024. All rights reserved.