沃梦达 / 编程问答 / php问题 / 正文

如何解决 AppRepositoriesFavoriteRepository::delete() 的缺

How to solve Missing argument 1 for AppRepositoriesFavoriteRepository::delete() ? (Laravel 5.3)(如何解决 AppRepositoriesFavoriteRepository::delete() 的缺失参数 1?(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() 的缺

基础教程推荐