title: Error in Laravel Too few arguments to function
body: <p>I am beginner in php and Laravel. I use in my project Laravel 7.
  I have repository pattern in my project with cache.</p>
  
  <p>PageServiceProvider:</p>
  
  <pre><code>public function register()
  {
      $this-&gt;app-&gt;bind(PageRepositoryInterface::class, function ($app) {
          return new CachingPageRepository(
              new PageRepository
          );
      });
  }
  
  public function provides()
  {
      return [
          PageRepositoryInterface::class,
      ];
  }
  </code></pre>
  
  <p>CachingBaseRepository:</p>
  
  <pre><code>abstract class CachingBaseRepository implements RepositoryInterface
  {
      use ScopeActiveTrait;
  
      protected $model;
  
      public function all()
      {
          return Cache::remember($this-&gt;model.'.all', $minutes = 10, function () {
              return $this-&gt;model-&gt;get();
          });
      }
  
      public function allEnables()
      {
          return Cache::remember($this-&gt;model.'.enables', $minutes = 10, function () {
              return $this-&gt;model-&gt;active()-&gt;get();
          });
      }
  
      public function list(string $orderByColumn, string $orderBy = 'desc', array $with = [])
      {
          return Cache::remember($this-&gt;model.'.list', $minutes = 10, function () use($with, $orderByColumn, $orderBy) {
              return $this-&gt;model-&gt;with($with)
                  -&gt;orderBy($orderByColumn, $orderBy)
                  -&gt;get();
          });
      }
  
      public function listWithPaginate(string $orderByColumn, string $orderBy = 'desc', array $with = [], int $perPage = 10)
      {
          return Cache::remember($this-&gt;model.'.listWithPaginate', $minutes = 10, function () use($with, $orderByColumn, $orderBy, $perPage) {
              return $this-&gt;model-&gt;with($with)
                  -&gt;orderBy($orderByColumn, $orderBy)
                  -&gt;paginate($perPage)-&gt;appends(request()-&gt;query());
          });
      }
  
      public function create(array $data): int
      {
          return $this-&gt;model-&gt;create($data)-&gt;id;
          // delete cache: all, enables, list, listWithPaginate
      }
  
      public function update(array $data, int $id, string $attribute = 'id'): void
      {
          $this-&gt;model-&gt;where($attribute, '=', $id)-&gt;update($data);
          // delete cache: all, enables, list, listWithPaginate
      }
  
      public function delete(int $id): void
      {
          $this-&gt;model-&gt;destroy($id);
          // delete cache: all, enables, list, listWithPaginate
      }
  
      public function find(int $id)
      {
          return Cache::remember($this-&gt;model.".{$id}", $minutes = 60, function () use ($id) {
              return $this-&gt;model-&gt;find($id);
          });
      }
  
      public function getModel()
      {
          return Cache::remember($this-&gt;model.".all", $minutes = 60, function (){
              return $this-&gt;model;
          });
      }
  
      public function getFirst(int $id)
      {
          return Cache::remember($this-&gt;model.".{$id}", $minutes = 60, function () use ($id) {
              return $this-&gt;model-&gt;where('id', $id)-&gt;first();
          });
      }
  
      public function findOrFail(int $id)
      {
          return Cache::remember($this-&gt;model.".{$id}", $minutes = 60, function () use ($id) {
              return $this-&gt;model-&gt;findOrFail($id);
          });
      }
  }
  </code></pre>
  
  <p>BaseRepository:</p>
  
  <pre><code>abstract class BaseRepository implements RepositoryInterface
  {
      use ScopeActiveTrait;
  
      protected $model;
  
      public function all()
      {
          return $this-&gt;model-&gt;get();
      }
  
      public function allEnables()
      {
          return $this-&gt;model-&gt;active()-&gt;get();
      }
  
      public function list(string $orderByColumn, string $orderBy = 'desc', array $with = [])
      {
          return $this-&gt;model-&gt;with($with)
              -&gt;orderBy($orderByColumn, $orderBy)
              -&gt;get();
      }
  
      public function listWithPaginate(string $orderByColumn, string $orderBy = 'desc', array $with = [], int $perPage = 10)
      {
          return $this-&gt;model-&gt;with($with)
              -&gt;orderBy($orderByColumn, $orderBy)
              -&gt;paginate($perPage)-&gt;appends(request()-&gt;query());
      }
  
      public function create(array $data): int
      {
          return $this-&gt;model-&gt;create($data)-&gt;id;
      }
  
      public function update(array $data, int $id, string $attribute = 'id'): void
      {
          $this-&gt;model-&gt;where($attribute, '=', $id)-&gt;update($data);
      }
  
      public function delete(int $id): void
      {
          $this-&gt;model-&gt;destroy($id);
      }
  
      public function find(int $id)
      {
          return $this-&gt;model-&gt;find($id);
      }
  
      public function getModel()
      {
          return $this-&gt;model;
      }
  
      public function getFirst(int $id)
      {
          return $this-&gt;model-&gt;where('id', $id)-&gt;first();
      }
  
      public function findOrFail(int $id)
      {
          return $this-&gt;model-&gt;findOrFail($id);
      }
  }
  </code></pre>
  
  <p>PageRepository:</p>
  
  <pre><code>class PageRepository extends BaseRepository implements PageRepositoryInterface
  {
  
      public function __construct(Page $model)
      {
          $this-&gt;model = $model;
      }
  
  
      public function search(string $query, string $orderByColumn, string $orderBy = 'desc', array $with = [], int $perPage = 10)
      {
          return $this-&gt;model-&gt;where('title', 'LIKE', '%' . $query . '%')-&gt;orWhere('description', 'LIKE', '%' . $query . '%')-&gt;orWhere('keywords', 'LIKE', '%' . $query . '%')-&gt;orWhere('content', 'LIKE', '%' . $query . '%')-&gt;with($with)-&gt;orderBy($orderByColumn, $orderBy)-&gt;paginate($perPage)-&gt;appends(request()-&gt;query());
      }
  
      public function getTextPageFromSlug(string $slug)
      {
          return $this-&gt;model-&gt;active()-&gt;where('slug', $slug)-&gt;first();
      }
  
  }
  </code></pre>
  
  <p>CachingPageRepository</p>
  
  <pre><code>class CachingPageRepository extends CachingBaseRepository implements PageRepositoryInterface
  {
      public function __construct(Page $model)
      {
          $this-&gt;model = $model;
      }
  
  
      public function search(string $query, string $orderByColumn, string $orderBy = 'desc', array $with = [], int $perPage = 10)
      {
          return Cache::remember('page.all', $minutes = 10, function () use($query, $orderByColumn, $with, $orderBy, $perPage) {
              return $this-&gt;model-&gt;where('title', 'LIKE', '%' . $query . '%')-&gt;orWhere('description', 'LIKE', '%' . $query . '%')-&gt;orWhere('keywords', 'LIKE', '%' . $query . '%')-&gt;orWhere('content', 'LIKE', '%' . $query . '%')-&gt;with($with)-&gt;orderBy($orderByColumn, $orderBy)-&gt;paginate($perPage)-&gt;appends(request()-&gt;query());
          });
      }
  
  
      public function getTextPageFromSlug(string $slug)
      {
          return Cache::remember("users.{$slug}", $minutes = 60, function () use ($slug) {
              return $this-&gt;model-&gt;active()-&gt;where('slug', $slug)-&gt;first();
          });
      }
  }
  </code></pre>
  
  <p>PageRepositoryInterface:</p>
  
  <pre><code>interface PageRepositoryInterface extends RepositoryInterface
  {
  
      public function search(string $query, string $orderByColumn, string $orderBy = 'desc', array $with = [], int $perPage = 30);
  
  
      public function getTextPageFromSlug(string $slug);
  
  }
  </code></pre>
  
  <p>I want to add cache to my website in the above code. My controller looks like this:</p>
  
  <pre><code>protected $model;
  
  
      public function __construct(PageRepositoryInterface $repository)
      {
          $this-&gt;model = $repository;
      }
  
  
      public function index(Request $request)
      {
          if ($request-&gt;input('query') != "") {
              $pages = $this-&gt;model-&gt;search($request-&gt;input('query'), 'id', 'asc', [],  30);
          } else {
              $pages = $this-&gt;model-&gt;listWithPaginate('id', 'desc', [],  30);
          }
          return view('admin.pages.list', ['pages' =&gt; $pages]);
      }
  </code></pre>
  
  <p>When I run the above code I get the error:</p>
  
  <blockquote>
    <p>ArgumentCountError Too few arguments to function
    App\Repositories\PageRepository::__construct(), 0 passed in
    /var/www/app/Providers/PageServiceProvider.php on line 22 and exactly
    1 expected</p>
  </blockquote>
  
  <p>Earlier, when I didn't have the cache on the page, my PageServiceProvider looked like this:</p>
  
  <pre><code>public function register()
      {
          $this-&gt;app-&gt;bind(
              PageRepositoryInterface::class,
              PageRepository::class
          );
      }
  </code></pre>
  
  <p>And the code ran without problems.</p>
  
  <p>How can I repair it?</p>
  
  <p>Please help me.</p>