gpt4 book ai didi

php - 为什么 Laravel 5.6 中没有删除表中的用户

转载 作者:行者123 更新时间:2023-11-29 09:57:43 26 4
gpt4 key购买 nike

我正在使用 Laravel 5.6 并以管理员身份从用户表中删除用户。我有以下 UserController 函数来删除表记录?

public function delete($id)
{
User::where('id', $id)->delete();

return redirect()
->back()
->with('info', 'User deleted successfully');
}

我的用户数据显示在索引 Blade 文件中,并带有如下的结束删除按钮:

<td>
<a class="button is-outlined"
href="{{route('users.index', $user->id.'/delete/')}}"
onclick="return confirm('Are you sure to want to delete this record?')"
>
Delete
</a>
</td>

我的删除路线是这样的,

Route::get('users/{users}/delete', [
'uses' => '\App\Http\Controllers\UserController@delete',
]);

但是现在,当我单击删除按钮 javascript 确认时,接受后仍然不会删除记录。 URL 更改如下:

http://localhost:8000/users?16/delete/     //16 is user id

如何解决这个问题?

最佳答案

将您的路线更改为:

Route::get('users/{id}/delete', [
'as' => 'users.delete','uses' => '\App\Http\Controllers\UserController@delete',
]);

更改以下行:

<td><a class="button is-outlined" href="{{route('users.index', $user->id.'/delete/')}}" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>

<td><a class="button is-outlined" href="{{route('users.delete',['id' => $user->id])}}" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>

关于php - 为什么 Laravel 5.6 中没有删除表中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53556435/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com