我是 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;
}
- 1 回答
- 0 關注
- 68 瀏覽
添加回答
舉報
0/150
提交
取消