How to solve Missing argument 1 for AppRepositoriesFavoriteRepository::delete() ? (Laravel 5.3)(如何解决 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
这篇关于如何解决 AppRepositoriesFavoriteRepository::delete() 的缺失参数 1?(Laravel 5.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何解决 AppRepositoriesFavoriteRepository::delete() 的缺
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01