Skip to content

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

License

Notifications You must be signed in to change notification settings

laravel-tech/repository-switcher

Repository files navigation

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();

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages