![](/img/trans.png)
[英]Pagination coming from AJAX request not working properly -- Laravel 5.6
[英]laravel 5.6 datatable pagination not working
我正在使用 laravel 5.6 並嘗試將分頁添加到引導數據表。 但它不起作用。我有錯誤。請幫我找出我做的錯誤。
錯誤
方法 Illuminate\\Database\\Eloquent\\Collection::links 不存在。
designation.blade.php(查看)
@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
名稱控制器.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);
}
}
您應該在控制器文件中使用 paginate() 方法。
public function index()
{
$designations = Designation::paginate(10);
return view('pages.designation')->with('designations',$designations);
}
您還可以對 Eloquent 查詢進行分頁。 在這個例子中,我們將用每頁 15 個項目對 User 模型進行分頁。 如您所見,語法幾乎與分頁查詢構建器結果相同:
$designations = Designation::paginate(15);
您可以在對查詢設置其他約束后調用 paginate,例如 where 子句:
$designations = Designation::where('column', 'value')->paginate(15);
您應該在控制器文件中使用 paginate() 方法。
public function index()
{
$designations = Designation::paginate(15);
return view('pages.designation')->compact('designations',$designations);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.