Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Last active November 22, 2016 03:22
Show Gist options
  • Save cuonghuynh/db3de30aa8af37ef2248031aad1370da to your computer and use it in GitHub Desktop.
Save cuonghuynh/db3de30aa8af37ef2248031aad1370da to your computer and use it in GitHub Desktop.
Repository pattern in laravel
<?php
namespace App\Contracts\Repository;
interface IRepository
{
/**
* Get all
* @param array $columns
* @return mixed
*/
public function all($columns = ["*"]);
/**
* Paginate all
* @param integer $perPage
* @param array $columns
* @return mixed
*/
public function paginate($perPage = 15, $columns = ['*']);
/**
* Create new model
* @param array $data
* @return mixed
*/
public function create($data = []);
/**
* Update model by the given ID
* @param array $data
* @param integer $id
* @param string $attribute
* @return mixed
*/
public function update($data = [], $id, $attribute = 'id');
/**
* Delete model by the given ID
* @param integer $id
* @return boolean
*/
public function delete($id);
/**
* Find model by the given ID
* @param integer $id
* @param array $columns
* @return mixed
*/
public function find($id, $columns = ['*']);
/**
* Find model by a specific column
* @param string $field
* @param mixed $value
* @param array $columns
* @return mixed
*/
public function findBy($field, $value, $columns = ['*']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment