为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel 存储库模式 - 关系错误

Laravel 存储库模式 - 关系错误

PHP
森林海 2022-10-28 09:36:38
我是 Laravel 和 php 的初学者。我在我的项目 Laravel 5.8 中有我的项目中的存储库亲子关系。我编写存储库基础、接口和控制器。我有这个代码:基础存储库:    abstract class BaseRepository implements RepositoryInterface    {        protected $model;        public function getAll(string $order = 'id', string $by = 'desc')        {            return $this->model->orderBy($order, $by)->get()->appends(request()->query());        }        public function getAllWithPaginate(string $order = 'id', string $by = 'desc', int $perPage = 1)        {            return $this->model->orderBy($order, $by)->paginate($perPage)->appends(request()->query());        }        public function with($relations)        {            return $this->model->with($relations);        }        public function create(array $data)        {            return $this->model->create($data);        }        public function save(array $data): int        {            $model = $this->model->create($data);            return $model->id;        }        public function update(array $data, int $id)        {            return $this->model->where("id", "=", $id)->update($data);        }        public function delete(int $id)        {            return $this->model->destroy($id);        }        public function find(int $id, string $order, string $by)        {            return $this->model->find($id)->orderBy($order, $by);        }        public function findOrFail(int $id, string $order, string $by)        {            return $this->model->findOrFail($id)->orderBy($order, $by);        }        public function getModel()        {            return $this->model;        }    }存储库接口:    interface RepositoryInterface    {        public function getAll(string $order, string $by);        public function getAllWithPaginate(string $order, string $by, int $perPage);        public function create(array $data);        public function save(array $data);    }当我运行我的代码时出现错误:调用未定义的方法 Illuminate\Database\Eloquent\Builder::getAllWithPaginate()我该如何解决?请帮我。
查看完整描述

1 回答

?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

尝试


public function with($relations)

{

    $this->model->with($relations);

    return $this;

}


查看完整回答
反对 回复 2022-10-28
  • 1 回答
  • 0 关注
  • 42 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信