PHPackages                             dees040/repository - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. dees040/repository

ActiveLibrary[Database &amp; ORM](/categories/database)

dees040/repository
==================

A Laravel package for the repository pattern.

0.1.10(5y ago)03111[1 issues](https://github.com/dees040/repository/issues)MITPHPCI failing

Since Oct 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/dees040/repository)[ Packagist](https://packagist.org/packages/dees040/repository)[ RSS](/packages/dees040-repository/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (5)Versions (16)Used By (0)

Laravel Repository Package
==========================

[](#laravel-repository-package)

**THIS PACKAGE IS A WORK IN PROGRESS**

This packages helps you to easily implement the repository package in your Laravel application.

**Why use this package out of the many other Laravel repository package?** This package was inspired by multiple other Laravel repository package. I took all the good things from those packages and create one unique package for it. Also I keep maintain this package, because I use it in multiple of my own projects.

Installation
------------

[](#installation)

You can install this package using composer, by running the following command:

```
composer require dees040/repository
```

The service provider is automatically added via Laravel package discovery.

Methods
-------

[](#methods)

**Dees040\\Repository\\Contracts\\Repository**

- `all($columns = ['*'])`
- `paginate($perPage = null, $columns = ['*'])`
- `first($columns = ['*'])`
- `find($id, $columns = ['*'])`
- `findOrFail($id, $columns = ['*'])`
- `findByField($field, $value, $columns = ['*'])`
- `findWhere(array $where, $columns = ['*'])`
- `findWhereIn(array $where, $columns = ['*'])`
- `firstOrCreate(array $attributes, array $values = [])`
- `create(array $attributes = [])`
- `insert(array $attributes = [])`
- `update($id, array $attributes)`
- `updateOrCreate(array $attributes, array $values = [])`
- `delete($id)`
- `deleteWhere(array $where)`
- `deleteWhereIn(array $where)`
- `orderBy($column, $direction = 'asc')`
- `with($relations)`
- `has($relation)`
- `whereHas($relation, \Closure $closure)`
- `orWhereHas($relation, \Closure $closure)`
- `sync($id, $relation, $attributes, $detaching = true)`
- `syncWithoutDetaching($id, $relation, $attributes)`

Usage
-----

[](#usage)

### Creating a repository

[](#creating-a-repository)

Repositories can be created by hand or via a command provided in this package. If you'd like to create a repository by hand you should create two files for each repository.

One class for the repository contract:

```
