亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 68 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號