Created
October 23, 2014 15:30
-
-
Save graymic/6db303d113d709f34e0e to your computer and use it in GitHub Desktop.
Laravel 4 Eloquent Repository Abstract
This file contains 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 app\Acme\Repositories; | |
/** | |
* Class EloquentRepository | |
* @package app\Acme\Repositories | |
*/ | |
abstract class EloquentRepository { | |
/** | |
* @var $model \Eloquent; | |
*/ | |
private $model; | |
/** | |
* @return \Eloquent | |
*/ | |
public function getModel() | |
{ | |
return $this->model; | |
} | |
/** | |
* @param $model | |
*/ | |
public function setModel($model) | |
{ | |
$this->model = $model; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function readAll() | |
{ | |
return $this->getModel()->all(); | |
} | |
/** | |
* @param array $attributes | |
* @return static | |
*/ | |
public function create(Array $attributes) | |
{ | |
$model = $this->getModel(); | |
return $model->create($attributes); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment