How to solve Missing argument 1 for App\Repositories\FavoriteRepository::delete() ? (Laravel 5.3)

爷,独闯天下 提交于 2019-11-27 04:55:26

问题


My service is like this :

public function delete($store_id)
{
    $result = $this->favorite_repository->delete($store_id);
    dd($result);
}

My repository is like this :

public function delete($store_id)
{
    $data = self::where('favoritable_id', $store_id)->delete();
    return $data;
} 

There exist error :

Missing argument 1 for App\Repositories\FavoriteRepository::delete(), called in C:\xampp\htdocs\mysystem\app\Repositories\FavoriteRepository.php on line 45 and defined

Can you help me?

UPDATE

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,
    ];
}

回答1:


Seems like you are using this pakage: nilportugues/eloquent-repository

If that is the case then you need to change the repository code to this:

public function delete($store_id)
{
    return $this->remove($store_id);
} 



回答2:


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



来源:https://stackoverflow.com/questions/41887504/how-to-solve-missing-argument-1-for-app-repositories-favoriterepositorydelete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!