Step 01: Changing index() method in ProfileController
public function index( Request $request ) { $meta_title = 'All Profiles'; $query = Profile::query(); $profiles = $query->orderBy( 'id', 'desc' )->paginate( 10 )->withQueryString(); return view( 'profiles.list', compact( 'meta_title','profiles' ) ); }
Step 02: Changing list.blade.php under views/resources/profiles folder for fetching and showing database rows using loop and adding a confirm delete modal for deleting a row of data
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="row">
<div class="col-md-4">
<h2 class="">All Profiles</h2>
</div>
<div class="col-md-4">
<div class="">
<form method="GET" action="{{ route('profiles.index' ) }}">
<input type="text" name="search_global" class="form-control" placeholder="Filter by name" value="{{ request('search_global', '') }}">
</form>
</div>
</div>
<div class="col-md-4 text-end pt-1">
<a class="btn btn-sm btn-primary" href="{{ route('products.create') }}"> Add Profile</a>
</div>
</div>
<table class="table mt-3">
<thead class="table-dark">
<tr>
<th>Id</th>
<th class="text-center">Name </th>
<th class="text-center">Created</th>
<th class="text-center">Order</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
@foreach ($profiles as $profile)
<tr>
<td>{{$profile->id}}</td>
<td class="text-center">{{$profile->name}}</td>
<td class="text-center">{{ date('y-m-d', strtotime($profile->created_at)) }}</td>
<td class="text-center" style="width:20%;">
<form action="{{ route('profiles.save_order',$profile->id) }}" method="POST" enctype="multipart/form-data">
@csrf
<input type="text" name="order" value="{{ $profile->sequence }}" data-post-id="{{ $profile->id }}" class="resource-order form-control text-center" placeholder="">
</form>
</td>
<td class="text-center">
<a class="text-black" href="{{ route('profiles.edit', $profile->id) }}"><i class="bi bi-pencil"></i></a>
<a class="text-black delete-row" href="javascript:void(0);" data-base-url="{{ echo url('') }}" data-rowname="{{ $profile->name }}" data-rowid="{{ $profile->id }}" data-resource="profiles"><i class="bi bi-trash"></i></a></td>
</td>
</tr>
@endforeach
@if (count($profiles) == 0)
<tr><td colspan="5"><span class="">Nothing found</span></td></tr>
@endif
</tbody>
</table>
<div class="justify-content-center mt-3">
{!! $profiles->links() !!}
</div>
</div>
</div>
</div>
<div id="modal-delete-confirm" class="modal fade">
<div class="modal-dialog modal-md modal-dialog-centered" >
<div class="modal-content" >
<div class="modal-header">
<h4><strong >Confirm Delete </strong></h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-hidden="true"></button>
</div>
<div class="modal-body text-center">
<p>Would you like to delete this row <span id="modal-delete-title"></span>? <br>Once deleted it cannot be reverted.</p>
<div class="row justify-content-center">
<div class="col-3">
<form id="list-frm-modal" class="float-start" method="POST" action="">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger white">Yes</button>
</form>
<a href="javascript:void(0);" class="btn btn-sm btn-info white float-end" data-bs-dismiss="modal">No</a>
</div>
</div>
</div>
</div>
</div>
</div>