laravel 应用程序\存储库\管理存储库::getAllAdmins():返回值的类型必须为Illuminate\Pagination\Paginator,返回的是LengthAwarePaginator

qcuzuvrc  于 2022-12-30  发布在  其他
关注(0)|答案(1)|浏览(167)

我使用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;
oyxsuwqo

oyxsuwqo1#

getAllAdmins()函数的结果是LengthAwarePaginator类型,因为Laravel分页函数返回该类型,而您的函数返回该类型。因此,您应该将返回类型更改为Illuminate\Pagination\LengthAwarePaginator,而不是Paginator

use Illuminate\Pagination\LengthAwarePaginator;

... 

public function getAllAdmins(int $count): LengthAwarePaginator
{
    return Admin::paginate($count);
}

相关问题