在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
1条答案
按热度按时间rqenqsqc1#
你应该加上
/
之前myads/{id}/delete
通过简单地添加/
在任何url的开头,它就变成了绝对url,可以从任何地方访问绝对位置,例如,如果您在localhost:8000/home 你点击了链接myads/{id}/delete
它将重定向到localhost:8000/home/myads/{id}/delete
这将产生冲突的路线,你提到了你的路线,并给出不想要的结果。