如何解决 AppRepositoriesFavoriteRepository::delete() 的缺失参数 1?(Laravel 5.3)
我的服务是这样的:
public function delete($store_id)
{
$result = $this->favorite_repository->delete($store_id);
dd($result);
}
我的仓库是这样的:
public function delete($store_id)
{
$data = self::where('favoritable_id', $store_id)->delete();
return $data;
}
存在错误:
缺少 AppRepositoriesFavoriteRepository::delete() 的参数 1,叫进来C:xampphtdocsmysystemappRepositoriesFavoriteRepository.php 上第 45 行并定义
Missing argument 1 for AppRepositoriesFavoriteRepository::delete(), called in C:xampphtdocsmysystemappRepositoriesFavoriteRepository.php on line 45 and defined
你能帮我吗?
更新
EloquentRepository 中的删除函数是这样的:
The delete function in the EloquentRepository is like this :
public function delete($id)
{
// Find the given instance
$deleted = false;
$instance = $id instanceof Model ? $id : $this->find($id);
if ($instance) {
// Delete the instance
$deleted = $instance->delete();
// Fire the deleted event
$this->getContainer('events')->fire($this->getRepositoryId().'.entity.deleted', [$this, $instance]);
}
return [
$deleted,
$instance,
];
}
推荐答案
您是否检查过哪个实例正在返回您的 self::where('favoritable_id', $store_id)
?它似乎正在返回您的 EloquentRepository 实例,而不是 Model 实例.区别在于EloquentRepository的delete方法是delete($id)
,Model的delete方法是delete()
.因此,您要么需要让 Model 实例使用 ->delete(),要么在您的实例上使用 ->delete($id)
Have you checked which instance is returning your self::where('favoritable_id', $store_id)
? It seems it is returning your EloquentRepository instance, instead of Model instance.
The difference is that EloquentRepository's delete method is delete($id)
, the Model's delete method is delete()
.
So you either need to get Model instance to use ->delete(), or use ->delete($id) on yours
相关文章