kyle-noland/laravel-base-repository

A flexible Laravel repository pattern foundation for working with Eloquent ORM
60 14
Install
composer require kyle-noland/laravel-base-repository
PHP:>=5.4.0
Last Updated:Feb 20, 2015
Links: GitHub  ·  Packagist
Maintainer: KyleNoland

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

404,034,618 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

384,821,166 4,658