如何解决 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)