为什么不删除Laravel 5.6中的数据表记录

时间:2018-11-11 08:02:40

标签: php mysql laravel-5

在Laravel 5.6应用程序中,我具有以下Controller功能来删除车辆表记录,

public function deleteOneAd($id)
    {
 DB::table('vehicles')
            ->where('id', $id)

            ->delete();
 return redirect()->back();  

我的删除按钮链接是

href="/myads/{{$vehicule->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>

和删除路径,

Route::get('myads/{id}/delete', [
    'uses' => '\App\Http\Controllers\VehicleController@deleteOneAd',
]);

但是当我单击删除按钮并遵循javascript消息删除记录时,它不起作用。我的意思是这不是删除。

myads刀片文件 请查看myads刀片视图

@forelse( $vehicles as $vehicule )


                    @if( $vehicule->uploads->count() > 0 )
                        <a href="{{ route('vehicles.show', $vehicule->id) }}">
                            @php
                                $upload = $vehicule->uploads->sortByDesc('id')->first();
                            @endphp
                            <img src="/images/{{ $upload->resized_name }}"></a>
                            {{$vehicule->provincename}}
                          {{$vehicule->milage}}
<br>

                           <td><a class="button is-outlined" href="{{route('vehicles.edit',$vehicule->id.'/edit/')}}" >Edit</a></td>
                            <td><a class="button is-outlined" href="/myads/{{$vehicule->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>
                        </a> 
                        <hr>
                    @endif

            @empty
                <td>No Advertisment to display.</td>
            @endforelse

1 个答案:

答案 0 :(得分:0)

Route::get('myads/{id}/delete', [
    'uses' => '\App\Http\Controllers\VehicleController@deleteOneAd',
]);

您应在/之前添加myads/{id}/delete 通过在任何url的开头简单地添加/,它就变成了绝对url,并且可以从任何地方访问到绝对位置,例如,如果您位于localhost:8000 / home页面,并且单击了指向{{1}的链接, }已链接,它将重定向到myads/{id}/delete,这将对您在路线中提到的路线产生冲突,并产生不必要的结果。