【问题标题】:I want to use the Delete route, but it is not supported. How can I use this route?我想使用删除路由,但不支持。我怎样才能使用这条路线?
【发布时间】:2019-08-29 06:14:06
【问题描述】:

我想删除从索引列表中选择的记录,但我在使用 deleteRoute 时遇到问题

web.php

Route::delete('/destroy/{id}', 'ProjectController@destroy')->name('despro');

控制器

public function destroy($id)
{
    Project::destroy($id);
    return redirect('/project');
}

index.blade.php

@foreach($view as $v)
    <tr>
        <td>{{$v->id}}</td>
        <td><a href="{{route('workindex', ['id' => $v->id])}}">{{$v->project_name}}</a></td>
        <td>{{$v->name}}</td>
        <td>{{$v->division}}</td>
        <td>{{$v->content}}</td>
        <td>{{$v->date}}</td>
        <td>{{$v->preferred_date}}</td>
        <td>{{$v->user_name}}</td>
        <td>
            @foreach($cats as $cat)
                @if($v->category_id == $cat->id)
                    {{$cat->name}}
                @endif
            @endforeach
        </td>
        <td>{{$v->status}}</td>
        <td>{{$v->estimated_work_time}}</td>
        <td><a href="{{url('/destroy', ['id' => $v->id])}}">delete</a></td>
    </tr>
@endforeach

将被删除并重定向到 index.blade.php 但是 此路由不支持 GET 方法。支持的方法:删除。 出来

【问题讨论】:

    标签: php


    【解决方案1】:

    删除路由需要DELETE方法。

    如果您使用的是 Laravel 5.1 或更高版本

    <form action="{{ route('despro', ['id' => $v->id]) }}" method="POST">
        {{ method_field('DELETE') }}
        {{ csrf_field() }}
        <button>delete</button>
    </form>
    

    如果你使用的是 Laravel 5.6 或更高版本,那么

     <form action="{{ route('despro', ['id' => $v->id]) }}" method="POST">
            @method('DELETE')
            @csrf
            <button>delete</button>
        </form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 2015-01-06
      • 2015-08-08
      • 2014-09-18
      • 1970-01-01
      相关资源
      最近更新 更多