Как удалить несколько записей в Laravel

Алгоритм действий представлен в данной статье

Во-первых: Вы создаете blade файл (contactlist.blade.php).
Затем отобразите список контактной информации с помощью флажка. После этого определите URL-адрес в форме.
Во-вторых: добавьте URL-адрес формы в файл маршрута web.php.
В-третьих: после этого Вы создаете контроллер с именем deletefileController.php и в этом файле создаете запрос о том, как удалить несколько ваших записей с помощью Laravel.

resources/views/contactlist.blade.php

<!DOCTYPE html>
<html>
<head>
<title>How to Delete Multiple Records in Laravel?</title>
</head>
<body>
<h1>How to Delete Multiple Records in Laravel?</h1>
<form method="post" action="{{url('multiplerecordsdelete')}}">
{{ csrf_field() }}
<div class="box-body">
<table>
<thead>
<tr>
<th><input type="checkbox" id="checkAll"> Select All</th>
</tr>
<tr>
<th>S.No.</th>
<th>Ckecked box</th>
<th>User Name</th>
</tr>
</thead>
<tbody>
<?php
$i=1;
foreach ($list as $key => $value) {
$name = $list[$key]->name;
?>
<tr>
<td>{{$i}}</td>
<td><input name='id[]' type="checkbox" id="checkItem" value="<?php echo $list[$key]->id; ?>">
<td>{{$name}}</td>
</tr>
<?php $i++; }?>
</tbody>
</table>
</div>
<input type="submit" name="submit" value="Delete All Data"/>
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script>
<script language="javascript">
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
</script>
</body>
</html>

routes/web.php

Route::get('contactlist', function () {
$list = DB::table('contact')->orderby('id', 'desc')->get();
return view('contactlist')->with('list', $list);
});
Route::post('multiplerecordsdelete', 'deletefileController@multiplerecordsdelete');

app/Http/Controllers/deletefileController.php 

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use App\Http\Controllers\Controller;
use DB;
use Redirect;
use View;
use File;
class deletefileController extends Controller
{
public function multiplerecordsdelete(Request $req)
{
$id = $req->id;
foreach ($id as $ke) {
DB::table('contact')->where('id', $ke)->delete();
}
return redirect()->back()->with('message','Successfully Delete Your Multiple Selected Records.');;
}
}


ВВЕРХ