通过单击表列中的用户 ID,我想使用 php 控制器升序或降序可以吗?
在控制器中
if(isset($_GET['sortOrder'])){
$reverse = ($_GET['sortOrder'] == 'desc') ? 'desc' : 'asc';
$okdata = DB::table('adminblogs')->orderBy('user_id', $reverse)->get();
return view("adminblog.index")->with("adminblogs", $okdata);
}
在视图中
<table id="example" class="table table-bordered">
<thead> <tr>
<th>ID</th>
<th>TITLE</th>
<th><a id="sort" href="{{url('admin?sortOrder=asc')}}">USER ID</a></th>
<th>DELETE</th>
</tr>
</thead>
<tbody>
@foreach($adminblogs as $blog)
<tr>
<td>{{ $blog->id }}</td>
<td>{{ $blog->title }}</td>
<td>{{ $blog->user_id }}</td>
<td>
@if(Auth::id() == $blog->user_id)
<a href="{{ url('admin/destroy/'.$blog->id.'/'.$blog->user_id) }}" class="btn btn-danger" >DELETE</a>
@else
<a href="{{ url('admin/destroy/'.$blog->id.'/'.$blog->user_id) }}" class="disabled btn btn-danger" >DELETE</a>
@endif
</td>
</tr>
@endforeach
胡说叔叔
有只小跳蛙