首页 > 解决方案 > 删除按钮从不返回或重定向(从不响应)

问题描述

首先我不得不点击一个删除按钮,但它什么也没返回,我不知道为什么。

它必须转到invoicesController.php文件上的删除功能并做我想做的任何事情。

这是我的发票控制器返回所有发票:

public function index()
{
    $invoice = invoices::all();

    return view('invoices.invoice')->with('in', $invoice);
}

这是我的刀片表:

<table id="example" class="table key-buttons text-md-nowrap">
    <thead>
        <tr>
            <th class="border-bottom-0">#</th>
            <th class="border-bottom-0">رقم الفاتورة</th>
            <th class="border-bottom-0">تاريخ الفاتورة</th>
            <th class="border-bottom-0">تاريخ الاستحقاق</th>
            <th class="border-bottom-0">المنتج</th>
            <th class="border-bottom-0">القسم</th>
            <th class="border-bottom-0">الخصم</th>
            <th class="border-bottom-0">نسبة الضريبة</th>
            <th class="border-bottom-0">قيمة الضريبة</th>
            <th class="border-bottom-0">الاجمالي</th>
            <th class="border-bottom-0">الحالة</th>
            <th class="border-bottom-0">ملاحظات</th>
            <th class="border-bottom-0">العمليات</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @php
            $a=0;
        @endphp
        @foreach ($in as $i)
            <tr>
                <td>{{ $a++ }}</td>
                <td>{{ $i->invoice_number }}</td>
                <td>{{ $i->invoice_date }}</td>
                <td>{{ $i->due_date }}</td>
                <td>{{ $i->product }}</td>
                <td>
                    <a href="{{ url('invoiceDetails') }}/{{ $i->id }}">{{ $i->section->section_name }}</a>
                </td>
                <td>{{ $i->discount }}</td>
                <td>{{ $i->rate_vat }}</td>
                <td>{{ $i->value_vat }}</td>
                <td>{{ $i->total }}</td>
                <td>
                    @if ($i->value_status == 1)
                        <span class="text-status">{{ $i->status }}</span>
                    @elseif($i->value_status == 2)
                        <span class="text-danger">{{ $i->status }}</span>
                    @else
                        <span class="text-warning">{{ $i->status }}</span>
                    @endif
                </td>
                <td>{{ $i->note }}</td>
                <td>
                    <a href="{{ route('in.edit' , $i->id) }}">edit</a>
    this is the issue                                       
                    <form action="{{ route('in.delete' , $i->id) }}" method="get">
                        @csrf
                        <input type="hidden" value="{{ $i->id }}">
                        <button type="button">delete</button>
                    </form>
                </td>
            </tr>
        @endforeach
    </tbody>
</table>

这是我的删除功能invoicesController

public function delete(Request $request)
{
    dd($request);
}

我的web.php

Route::post('in/{id}', [App\Http\Controllers\InvoicesController::class, 'delete'])
    ->name('in.delete');

标签: phplaravel

解决方案


首先,将您的web.php路线从更改postdelete

Route::delete('in/{id}', [App\Http\Controllers\InvoicesController::class, 'delete'])
    ->name('in.delete');

其次,将您的表单method从更改getPOST

<form action="{{ route('in.delete', $i->id) }}" method="POST">

最后,在那个确切的<form>标签之后和之前@csrf,添加一个新的刀片指令,它将“模拟”你发送这个表单DELETE

<form action="{{ route('in.delete', $i->id) }}" method="POST">
    @method('DELETE')
    @csrf

@method您可以在此处阅读更多信息。


推荐阅读