简体   繁体   English

删除功能Laravel 5.2

[英]delete function Laravel 5.2

I've been learning laravel 5.2 recently, and i've made a delete function which should delete records from my database but instead of deleteing the records it's adding a blank row into my database 我最近一直在学习laravel 5.2,并且我做了一个delete函数,该函数应该从数据库中删除记录,但是与其删除记录,不如将其添加到数据库中的空白行

This is the Route im using: 这是Route im使用的:

Route::resource('producten', 'ProductenController', ['only' => ['index', 'store', 'destroy', 'edit', 'update', 'create']]);

This is the controller function i use for it 这是我使用的控制器功能

 public function destroy(request $request , product $product)
{
    $product->delete();

    return redirect(Route('producten.index'));
}

This is the form i've made for it. 这是我为此制作的表格。

 {{ Form::Open(['Route' => 'producten.destroy', $product], ['method' => 'delete']) }}
                 {{ Form::Submit('delete')}}
              {{ Form::close() }}

when i viewed the source-code it said it was using a POST method instead of a delete method, and also when i add($product) i got a blank page, also i found out that when i hit the submit button it goes to the store method i've made and i dont know why, 当我查看源代码时,它说它使用的是POST方法而不是删除方法,而且当我添加($ product)时,我得到一个空白页,我也发现当我按下“提交”按钮时,它转到我做过的存储方法,我不知道为什么,

if u need more information just let me know and i'll add it in the question 如果您需要更多信息,请让我知道,我将其添加到问题中

route and method should be in the same array, not in two differents arrays. route和method应该在同一数组中,而不是在两个不同的数组中。

{{ Form::Open(['method' => 'DELETE', 'route' => ['producten.destroy', $product]]) }}
    {{ method_field('DELETE') }}
    {{ Form::Submit('delete')}}
{{ Form::close() }}

I think you have something wrong with form. 我认为您的表格有问题。 Can you try with this: 您可以尝试一下:

<form action="{{ route('producten.destroy', ['product' => $product->id]) }}" method="POST">
    {{ csrf_field() }}
    {{ method_field('DELETE') }}

    <button type="submit">Remove</button>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM