Laravel在警报中确认删除 [英] Laravel confirm delete in an alert
问题描述
这应该是一个简单的任务我还没有完全掌握laravel。
我有我的控制器视图和模型设置。我想使用我的users.destroy路由删除我在db中的行。但我想以某种方式做到这一点。我希望在我的页面上的警报区域中有一个警报显示,要求确认删除某个用户。我假设我需要将会话中的用户ID传递给警报,以确认我在删除按钮上的删除单击。
如果单击确认,单击1按钮在我的页面顶部打开警报它调用user.destroy。
This should be a simple task I am just not fully grasping laravel yet.
I have my controllers view and models setup. I want to use my users.destroy route to delete my row in the db. But I want to do it a certain way. I want to have an alert show In my alert area on my page asking to confirm the deletion of a certain user. Im assuming I need to pass the user id in a session to an alert to confirm my delete on a delete button click.
Click 1 button to open an alert on the top of my page if I click confirm it calls user.destroy.
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4>View All Users</h4>
@if(session()->get('success'))
<div class="alert alert-success">
{{ session()->get('success') }}
</div>
@endif
@if(session()->get('danger'))
<div class="alert alert-danger">
{{ session()->get('danger') }}
</div>
@endif
</div>
<div class="card-body">
<div class="text-center my-2">
<a href="{{ route('register') }}" class="btn btn-primary">New User</a>
</div>
<div>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Username</th>
<th colspan="2">Actions</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<th>{{$user->id}}</th>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{$user->username}}</td>
<td class="text-center">
<a href="{{ route('users.show', $user->id) }}" class="btn btn-primary mr-3">Show</a>
<a href="{{ route('users.edit', $user->id) }}" class="btn btn-info text-white ml-3">Edit</a>
<a href="#" class="btn btn-danger">Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
public function destroy($id)
{
User::find($id)->delete();
return redirect()->route('users.index')->with('success','User Deleted');
}
Route::resource('users', 'UserController');
什么我试过了:
使用会话我假设带上我的id $ user-> id并把它放在我的警报中所以我可以打电话给我在我的控制器中的users.destroy方法确认删除
What I have tried:
using a session im assuming to bring my id $user->id and put that in my alert so i can call my users.destroy method in my controller to have a confirmation of deleting
推荐答案
用户为
用户)
< span class =code-keyword>< tr >
< th > {{
user) <tr> <th>{{
user-> id}} < / th < span class =code-keyword>>
< td > {{
user->id}}</th> <td>{{
这篇关于Laravel在警报中确认删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!