Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 619 Bytes

README.md

File metadata and controls

18 lines (16 loc) · 619 Bytes

Repository Switcher

A repository pattern example for Laravel to switch between eloquent and query builder.

Steps

  1. Define repository classes and interfaces in app\Repositories directory.
  2. Define a constructor in all controllers:
public function __construct(StrategyContext $strategy)
   {
      parent::__construct($strategy);
      $this->strategy->repository(ArticleRepositoryInterface::class);
   }
  1. Call method of the repository like the following example:
    $querybuilderData = $this->strategy->querybuilder()->list();
    OR
    $eloquentData = $this->strategy->eloquent()->list();