Я создал приложение todo в laravel, в котором есть кнопка удаления.Всякий раз, когда я добавляю данные, это работает, показывает в таблице.Но после нажатия кнопки «Удалить» другие данные отображаются не в таблице.
![enter image description here](https://i.stack.imgur.com/qwi76.png)
ToDosController
public function index(Request $request)
{
$userid = $request->user()->todos()->get(['id']);
$arr = ToDo::whereIn('user_id', $userid)->paginate(5);
$count['counts'] = ToDo::whereIn('user_id', $userid);
$pending = ToDo::where('status', 'Pending');
$completed = ToDo::where('status', 'Completed');
return view('admin.todo.index')->with('todos',$arr)->with($count)->with('pending',$pending)->with('completed',$completed)->with((array('user' => Auth::user())));
}
public function destroy($id) {
$todo = ToDo::find($id);
$todo->delete();
return redirect()->route('admin.todo.index')->with('success', 'Deleted Successfully');
}
Просмотр
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tr>
<th>Status</th>
<th>Title</th>
<th>Description</th>
<th>Schedule</th>
<th>Deadline</th>
<th>Action</th>
</tr>
@if(count($todos) > 0)
@foreach($todos as $td)
<tr>
<td>
@if($td->status == 'Pending')
<span class="label label-danger">{{ $td->status }}</span></td>
@elseif($td->status == 'Completed')
<span class="label label-success">{{ $td->status }}</span></td>
@endif
</td>
<td>{{ $td->title }}</td>
<td>{{ $td->description }}</td>
<td>{{ $td->schedule }}</td>
<td>{{ $td->deadline }}</td>
<td>
<a href="{{route('admin.todo.edit',$td->id)}}" class="btn btn-info">Edit</a>
<a href="javascript:void(0)" onClick="$(this).parent().find('form').submit()" class="btn btn-danger">Delete</a>
<a href="{{ route('admin.todo.show',$td->id) }}" class="btn btn-info">Show</a>
<form action="{{route('admin.todo.destroy',$td->id)}}" method="post" value="DELETE">
{{ csrf_field() }}
{{ method_field('DELETE') }}
</form>
</td>
</tr>
@endforeach
На изображении видно, что он показывает ожидающие задачи, завершенные задачи, но не показывает их в таблице.