我正在使用 laravel 5.6 并尝试向引导数据表添加分页。但它不起作用。我遇到了错误。请帮助我找出我犯的错误。
错误
Method Illuminate\Database\Eloquent\Collection::links does not exist.
designation.blade.php( View )
@if(count($designations)>=1)
<table class="table table-dark" id="designationTable">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Designation Type</th>
<th scope="col">Status</th>
<th scope="col">Create At</th>
<th scope="col">Action</th>
</tr>
</thead>
@foreach ($designations as $designation)
<tbody>
<tr>
<th scope="row">{{$designation->id}}</th>
<td>{{$designation->designation_type}}</td>
<td>{{$designation->status}}</td>
<td>{{$designation->created_at}}</td>
<td>
<button type="" class="btn btn-secondary" id="btn_update_designation">Update</button>
</td>
</tr>
</tbody>
@endforeach
</table>
{{ $designations->links() }}
@endif
DesignationController.php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use App\Designation;
class DesignationController extends Controller
{
public function index()
{
$designations = Designation::all();
return view('pages.designation')->with('designations',$designations);
}
}
最佳答案
您应该在 Controller 文件中使用 paginate() 方法。
public function index()
{
$designations = Designation::paginate(10);
return view('pages.designation')->with('designations',$designations);
}
关于php - laravel 5.6 数据表分页不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59767647/