skip to Main Content

At the most basic understanding, I’ve been trying to match the route and the form action. I think that I am doing it right but I wonder why the error keeps on showing. I may have missed something anywhere but I just really couldn’t find it. Please help. With a very tight schedule, I need to complete this project.

When I submit the form it goes to this address.

index.blade.php

<tbody>
@foreach($payments as $payment)
    <tr>
        <td>{{ $payment->order->first_last_name }}</td>
        <td>{{ $payment->order->business_name }}</td>
        <td>{{ $payment->order->business_type }}</td>
        <td>{{ $payment->order->phone_number }}</td>
        <td>{{ $payment->order->postal_code }}</td>
        <td>{{ $payment->order->email }}</td>
        <td>{{ $payment->order->address }}</td>
            <button type="button" class="btn btn-success btn-sm" data-action="{{ route('payments.send', $payment->id) }}" data-bs-toggle="modal" data-bs-target="#send" data-id="{{ $payment->id }}">اSend</button>
        </td>
        <td>
            @php $status = $payment->status @endphp
            <span class="{{ $status['bs_class'] }}">
                    {{ $status['label'] }}
                </span>
        </td>
        <td>{{ $payment->accounting_code   }}</td>
    </tr>
    @include('Admin.layouts.modal')
@endforeach
</tbody>

js

<script>
    $('#send').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var action = button.data('action');
        var orderId = button.data('id');
        var modal = $(this);
        modal.find('form').attr('action', action);
        document.getElementById("orderId").value = orderId;
    });
</script>

modal.blade.php

<div class="modal fade" id="send" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="send" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content"> 
            <form action="{{ route('payments.accounting', $payment->id) }}" method="post">
                @csrf
                @method('PUT')
                <input type="hidden" id="orderId" value="">
                <div class="modal-header">
                    <h5 class="modal-title" id="sendTitle">send</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="accounting_code" class="form-label">کد accounting_code</label>
                        <input type="text" class="form-control" id="accounting_code" name="accounting_code">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success">save</button>
                </div>
            </form>
        </div>
    </div>
</div>

web.php

  Route::put('/payments/accounting/{payment}', [AppHttpControllersAdminPaymentController::class,'accounting'])->name('payments.accounting');

PaymentController.php

public function accounting(Payment $payment, Request $request)
{
    dd('hello');
    $data = [
        'accounting_code' => $request->post('accounting_code')
    ];
    $payment->update($data);
    return back();
}

2

Answers


  1. Did you try it without naming the route?

    delete this:

    ->name('payments.accounting')
    

    and then in HTML form:

    action="/payments/accounting"
    

    I think you are mixing POST, PUT and GET Request here. Make sure you send your form with the correct method.

    Login or Signup to reply.
  2. Because your js code modal.find('form').attr('action', action) replaced the form action when showing the modal. Try to change the data-action from route payments.send to payments.accounting for the send button:

    <button type="button" class="btn btn-success btn-sm" data-action="{{ route('payments.accounting', $payment->id) }}" data-bs-toggle="modal" data-bs-target="#send" data-id="{{ $payment->id }}">اSend</button>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search