Skip to content

Instantly share code, notes, and snippets.

@graymic
Created October 23, 2014 15:30
Show Gist options
  • Save graymic/6db303d113d709f34e0e to your computer and use it in GitHub Desktop.
Save graymic/6db303d113d709f34e0e to your computer and use it in GitHub Desktop.
Laravel 4 Eloquent Repository Abstract
<?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