为什么没有在Laravel5.6中删除数据表记录

sd2nnvve  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(323)

在laravel 5.6应用程序中,我有以下控制器功能来删除车辆表记录,

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 blade文件请查看myads blade视图

@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
rqenqsqc

rqenqsqc1#

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

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

相关问题