[英]How to stay on same page if a record delete from table in laravel 5.4?
I have multiple records in my database table Now, what I want when I click on a specific record delete button then the record will be deleted and the page will be stay on the same page without redirect anywhere. 我的数据库表中有多条记录现在,当我点击特定记录删除按钮时我想要的内容然后记录将被删除,页面将保留在同一页面上,而不会在任何地方重定向。 So, How can I do this?
那么,我该怎么办呢? Please help me.
请帮我。
controller: UserController.php controller:UserController.php
public function delete_emp($id)
{
DB::delete('delete from emp where id = ?',[$id]);
}
view: emp-list.blade.php 查看:emp-list.blade.php
<table class="table">
<thead>
<tr>
<th>Full Name</th>
<th>Email</th>
<th>Phone</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($result as $row)
<tr>
<td>{{ $row->fname }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->phone }}</td>
<td>
<a href="{{url('/delete_emp')}}/{{ $row->id }}" class="btn btn-danger" onclick="return confirm('are you sure')">Delete</a>
</td>
</tr>
@endforeach
</tbody>
</table>
route/web.php 路线/ web.php
Route::get('delete_emp/{id}','UserController@delete_emp');
in your UserController.php, just add one line below the query 在您的UserController.php中,只需在查询下方添加一行
public function delete_emp($id)
{
DB::delete('delete from emp where id = ?',[$id]);
return redirect()->back();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.