Created
February 8, 2014 08:50
-
-
Save coreymcmahon/8878753 to your computer and use it in GitHub Desktop.
A Pattern for Reusable Repository Design in Laravel - http://www.slashnode.com/reusable-repository-design-in-laravel/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Acme\Abstracts; | |
use Acme\Repositories\RepositoryInterface; | |
/** | |
* The Abstract Repository provides default implementations of the methods defined | |
* in the base repository interface. These simply delegate static function calls | |
* to the right eloquent model based on the $modelClassName. | |
*/ | |
abstract class Repository implements RepositoryInterface { | |
protected $modelClassName; | |
public function create(array $attributes) | |
{ | |
return call_user_func_array("{$this->modelClassName}::create", array($attributes)); | |
} | |
public function all($columns = array('*')) | |
{ | |
return call_user_func_array("{$this->modelClassName}::all", array($columns)); | |
} | |
public function find($id, $columns = array('*')) | |
{ | |
return call_user_func_array("{$this->modelClassName}::find", array($id, $columns)); | |
} | |
public function destroy($ids) | |
{ | |
return call_user_func_array("{$this->modelClassName}::destroy", array($ids)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment