LaravelPackages.net
Acme Inc.
Toggle sidebar
kyle-noland/laravel-base-repository

A flexible Laravel repository pattern foundation for working with Eloquent ORM

60
14
About kyle-noland/laravel-base-repository

kyle-noland/laravel-base-repository is a Laravel package for a flexible laravel repository pattern foundation for working with eloquent orm. It currently has 14 GitHub stars and 60 downloads on Packagist. Install it with composer require kyle-noland/laravel-base-repository. Discover more Laravel packages by kyle-noland or browse all Laravel packages to compare alternatives.

Last updated

laravel-base-repository

A flexible Laravel repository pattern foundation for working with Eloquent ORM.

The goal of this package is to provide a foundation for building Laravel Eloquent repositories while still allowing you to create basic queries on the fly.

Installation

Install this package through Compposer. Edit your project's composer.json file to require kyle-noland/laravel-base-repository

"require": {
    "kyle-noland/laravel-base-repository": "dev-master"
}

Update Composer from the Terminal

composer update

Add the Service Provider to your app/config/app.php file

'KyleNoland\LaravelBaseRepository\LaravelBaseRepositoryServiceProvider'

Usage

Extend the BaseRepository class and implement your own custom repository logic:

<?php namespace MyProject\Repositories;

use KyleNoland\LaravelBaseRepository\BaseRepository;
use MyProject\Interfaces\CompanyRepositoryInterface;
use MyProject\Models\Company;

class CompanyRepository extends BaseRepository implements CompanyRepositoryInterface {

	public function __construct(Company $model)
	{
		$this->model = $model;
	}
	
	// Add your repository methods here

}

The BaseRepository class provides basic COUNT, SELECT, INSERT, UPDATE, DELETE, WHERE, WHERE IN clauses and the ability to eager load related models.

Counting All Models

$count = $this->companyRepo->count();

Counting a Subset of Models

$count = $this->companyRepo->where('is_active', true)->count();

Selecting Models

$allCompanies = $this->companyRepo->all();
$activeCompanies = $this->companyRepo->where('is_active', true)->get();
$activeCopmaniesInTexas = $this->companyRepo->where('is_active', true)->where('state', 'TX')->get();
Comments