php - 删除按钮从不返回或重定向(从不响应)
问题描述
首先我不得不点击一个删除按钮,但它什么也没返回,我不知道为什么。
它必须转到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');
解决方案
首先,将您的web.php
路线从更改post
为delete
:
Route::delete('in/{id}', [App\Http\Controllers\InvoicesController::class, 'delete'])
->name('in.delete');
其次,将您的表单method
从更改get
为POST
:
<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
您可以在此处阅读更多信息。
推荐阅读
- typescript - Define a recursive array of even length in TypeScript
- javascript - 如何禁用切换按钮?
- python - Pandas lookup within groupby dataframe
- powershell - Windows 10 Powershell Automation Script Issue
- php - Gutenberg Blocks:使用 `register_block_type_from_metadata()` 注册多个块会在控制台中引发错误
- cryptography - How to derive RSA key from PGP key JavaScript?
- boost - boost Spirit x3 的编译性能问题
- android - 如何在android studio的前台添加motionSensor
- javascript - 添加未版本化的 js 构建文件时,WebStorm 变得非常慢
- kubernetes - 识别持久卷声明的节点