我是 Laravel 和 php 的初學(xué)者。我在我的項(xiàng)目 Laravel 5.8 中有我的項(xiàng)目中的存儲庫親子關(guān)系。我編寫存儲庫基礎(chǔ)、接口和控制器。我有這個代碼:基礎(chǔ)存儲庫: 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); }當(dāng)我運(yùn)行我的代碼時出現(xiàn)錯誤:調(diào)用未定義的方法 Illuminate\Database\Eloquent\Builder::getAllWithPaginate()我該如何解決?請幫我。
1 回答

牛魔王的故事
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個贊
嘗試
public function with($relations)
{
$this->model->with($relations);
return $this;
}
- 1 回答
- 0 關(guān)注
- 71 瀏覽
添加回答
舉報
0/150
提交
取消