我使用paginate
来显示数据库数据,但是得到了以下错误App\Repositories\AdminRepository::getAllAdmins(): Return value must be of type Illuminate\Pagination\Paginator, Illuminate\Pagination\LengthAwarePaginator returned
我应该使用什么名称空间来修复它?
这是我的AdminRepository.php
<?php
namespace App\Repositories;
use App\Repositories\Interfaces\AdminRepositoryInterface as AdminRepositoryInterface;
use Illuminate\Database\QueryException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;
use App\Models\Admin;
use Illuminate\Support\Facades\Hash;
use App\Http\Requests\EditPassword;
use Illuminate\Contracts\View\View;
use App\Http\Requests\CreateAdmin;
use App\Http\Requests\DeleteAdmin;
use App\Http\Requests\EditAdmin;
use App\Services\AdminService;
use Illuminate\Http\Request;
class AdminRepository implements AdminRepositoryInterface
{
public function getAllAdmins(int $count):Illuminate\Pagination\AbstractPaginator
{
return Admin::paginate($count);
}
这是我的AdminRepositoryInterface.php
namespace App\Repositories\Interfaces;
use App\Models\Admin;
use Illuminate\Http\RedirectResponse;
interface AdminRepositoryInterface
{
public function getAllAdmins(int $count):Illuminate\Pagination\AbstractPaginator;
1条答案
按热度按时间oyxsuwqo1#
getAllAdmins()
函数的结果是LengthAwarePaginator
类型,因为Laravel分页函数返回该类型,而您的函数返回该类型。因此,您应该将返回类型更改为Illuminate\Pagination\LengthAwarePaginator
,而不是Paginator
。