亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 中的錯誤函數參數太少

Laravel 中的錯誤函數參數太少

PHP
飲歌長嘯 2023-04-15 20:53:45
我是 php 和 Laravel 的初學者。我在我的項目 Laravel 7 中使用。我的項目中有帶有緩存的存儲庫模式。頁面服務提供者:public function register(){    $this->app->bind(PageRepositoryInterface::class, function ($app) {        return new CachingPageRepository(            new PageRepository        );    });}public function provides(){    return [        PageRepositoryInterface::class,    ];}緩存庫:abstract class CachingBaseRepository implements RepositoryInterface{    use ScopeActiveTrait;    protected $model;    public function all()    {        return Cache::remember($this->model.'.all', $minutes = 10, function () {            return $this->model->get();        });    }    public function allEnables()    {        return Cache::remember($this->model.'.enables', $minutes = 10, function () {            return $this->model->active()->get();        });    }    public function list(string $orderByColumn, string $orderBy = 'desc', array $with = [])    {        return Cache::remember($this->model.'.list', $minutes = 10, function () use($with, $orderByColumn, $orderBy) {            return $this->model->with($with)                ->orderBy($orderByColumn, $orderBy)                ->get();        });    }    public function listWithPaginate(string $orderByColumn, string $orderBy = 'desc', array $with = [], int $perPage = 10)    {        return Cache::remember($this->model.'.listWithPaginate', $minutes = 10, function () use($with, $orderByColumn, $orderBy, $perPage) {            return $this->model->with($with)                ->orderBy($orderByColumn, $orderBy)                ->paginate($perPage)->appends(request()->query());        });    }    public function create(array $data): int    {        return $this->model->create($data)->id;        // delete cache: all, enables, list, listWithPaginate    }
查看完整描述

1 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

從 PageRepository 中的 _construct,你的 $model 是一個頁面。構造函數需要模型/頁面來實例化一個新的 PageRepository:


public function register()

{

    $this->app->bind(PageRepositoryInterface::class, function ($app) {

        return new CachingPageRepository(

            new PageRepository(new Page())  //constructor for PageRepository needs a model

        );

    });

}


public function provides()

{

    return [

        PageRepositoryInterface::class,

    ];

我把“new Page()”放在那里,但我真的不知道你從哪里得到你的新頁面實例。但是,從構造函數中可以清楚地看出,您需要在那里輸入一個 Page 實例:


public function __construct(Page $model) 

{

    $this->model = $model;

}


查看完整回答
反對 回復 2023-04-15
  • 1 回答
  • 0 關注
  • 99 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號