dev-master
9999999-devA flexible Laravel repository pattern foundation for working with Eloquent ORM
The Requires
- php >=5.4.0
- illuminate/support 4.2.*
by Kyle Noland
Wallogit.com
2017 © Pedro Peláez
A flexible Laravel repository pattern foundation for working with Eloquent ORM
A flexible Laravel repository pattern foundation for working with Eloquent ORM., (*1)
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., (*2)
Install this package through Compposer. Edit your project's composer.json file to require kyle-noland/laravel-base-repository, (*3)
``` json "require": { "kyle-noland/laravel-base-repository": "dev-master" }, (*4)
Update Composer from the Terminal
composer update, (*5)
Add the Service Provider to your app/config/app.php file ``` php 'KyleNoland\LaravelBaseRepository\LaravelBaseRepositoryServiceProvider'
Extend the BaseRepository class and implement your own custom repository logic:, (*6)
``` php <?php namespace MyProject\Repositories;, (*7)
use KyleNoland\LaravelBaseRepository\BaseRepository; use MyProject\Interfaces\CompanyRepositoryInterface; use MyProject\Models\Company;, (*8)
class CompanyRepository extends BaseRepository implements CompanyRepositoryInterface {, (*9)
public function __construct(Company $model)
{
$this->model = $model;
}
// Add your repository methods here
}, (*10)
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 ``` php $count = $this->companyRepo->count();
``` php $count = $this->companyRepo->where('is_active', true)->count();, (*11)
### Selecting Models ``` php $allCompanies = $this->companyRepo->all(); $activeCompanies = $this->companyRepo->where('is_active', true)->get(); $activeCopmaniesInTexas = $this->companyRepo->where('is_active', true)->where('state', 'TX')->get();
A flexible Laravel repository pattern foundation for working with Eloquent ORM