其他资源路由,例如order
和product
控制器索引功能正在工作并显示索引页面
但是当我请求类别索引页面laravel 5.8时说
方法Illuminate \ Database \ Eloquent \ Collection :: currentPage不存在视图category / index.php
这是除类别控制器之外用于所有其他路由的路由组,用于显示来自索引功能的索引页和用于索引功能的仪表板
Route::group(['prefix' => 'dashboard', 'namespace' => 'Dashboard', 'middlware' => ['auth:admin']], function () {
Route::name('dashboard.')->group(function () {
Route::resource('/', 'DashboardController');
Route::resource('/products', 'ProductController'); // ->except(['create', 'index']);
Route::resource('/categories', 'categoryController'); // ->except(['create', 'index']);
Route::resource('/orders', 'orderController'); // ->except(['create', 'index']);
});
});
它们工作得很好,但是当我配置多重身份验证并进行管理员身份验证时,它开始显示这些错误
如果有人从事laravel5.8
答案 0 :(得分:1)
您正在从currentPage实例而不是collection实例上使用方法来静态调用LengthAwarePaginator属性
您的控制器必须返回分页查询构建器实例Illuminate\Pagination\LengthAwarePaginator
,如
class categoryController extends Controller
{
public function index()
{
$categories = \DB::table('categories')->orderByDesc('id')->paginate(4);
return view('dashboard.categories.index', compact('categories'));
}
}
然后在您的dashboard/categories/index
视图中,将currentPage()
用作函数
{{ $categories->currentPage() }}
从docs
答案 1 :(得分:0)
zahid hasan emon bro这是我的控制器
class categorycontroller extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$data = [];
// $data['categories'] = \DB::table('categories')->get();
$data['categories'] = \DB::table('categories')->orderByDesc('id')->paginate(4);
return view('dashboard.categories.index',$data);
}
这是我的分类页面
@section('page-subtitle','List of all categories')
@section('content')
<div class="box">
<div class="box-header with-border">
<h3 class="box-title"></h3>
<a href="{{route('dashboard.categories.create')}}" class="btn btn-primary">New Category</a>
<div class="box-tools pull-right">
{{(($categories->currentPage() * $categories->perPage())- $categories->perPage() )+1 }}
of {{$categories->total()}}
</div>
</div>
<div class="box-body">
<table class="table table-condensed table-striped table-responsive">
<tr>
<td>ID</td>
<td>Name</td>
<td>Action</td>
</tr>
@forelse($categories as $category)
<tr>
<td>{{$category->id}}</td>
<td>{{$category->name}}</td>
<td>
<div class="action-box">
<a href="{{route('dashboard.categories.edit',$category->id)}}"><i class="fa fa-edit"></i></a>
<a href=""><i class="fa fa-remove"></i></a>
</div>
</td>
</tr>
@empty
<tr class="text-center warning">
<td colspan="3">No Record Found</td>
</tr>
@endforelse
</table>
</div>
<!-- /.box-body -->
<div class="box-footer">
@if(count($categories))
<div class="pull-left">
{{$categories->links()}}
</div>
@endif
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
@endsection
我认为我用来显示页数的currentpage()方法造成了问题,但是在进行多重身份验证之前效果很好