从模态的Laravel帖子尝试获取GET而不是POSt

模态从@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
评论
你太小
你太小

$org is not what you want in your modal: it is the last $org from your loop over your $orgs array since it is not inside the @foreach loop.

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

点赞
评论