🔒 Closed Show history using Modal

Status
Not open for further replies.
To show all the soft-deleted table rows in a modal using Laravel, you can follow these steps:

1. Create a modal in your view file where you want to display the soft-deleted rows.

2. In your controller, you can fetch all the soft-deleted rows using Laravel's withTrashed() method on your model.

3. Pass the fetched data to your view.

4. In your view, you can loop through the data and display it in your modal.

Here is an example code snippet that demonstrates the above process:

View file:

Code:
<!-- Your button to open the modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#softDeletedRowsModal">
  Open Modal
</button>

<!-- Your modal -->
<div class="modal" id="softDeletedRowsModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Soft Deleted Rows</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <div class="modal-body">
        <table class="table">
          <thead>
            <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Deleted At</th>
            </tr>
          </thead>
          <tbody>
            @foreach($softDeletedRows as $row)
              <tr>
                <td>{{ $row->id }}</td>
                <td>{{ $row->name }}</td>
                <td>{{ $row->deleted_at }}</td>
              </tr>
            @endforeach
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

Controller method:

Code:
public function showSoftDeletedRowsInModal()
{
    $softDeletedRows = YourModel::withTrashed()->get();

    return view('your-view-file', compact('softDeletedRows'));
}

Make sure to replace YourModel with your actual model name and 'your-view-file' with your view file name.

I hope this helps!
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 283
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
544
Guests online
1,197
Total visitors
1,741

Forum statistics

Threads
2,273,554
Posts
28,950,330
Members
1,235,814
Latest member
najnaj282828
Back
Top