Last active
August 29, 2015 14:15
-
-
Save muratsplat/dd1efb3735caf7f8c6c0 to your computer and use it in GitHub Desktop.
Revisions
-
muratsplat renamed this gist
Feb 11, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
muratsplat revised this gist
Feb 11, 2015 . No changes.There are no files selected for viewing
-
muratsplat created this gist
Feb 11, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,108 @@ <?php namespace Boruu\Root\Mvc\Repository; /** * Core Repository for Eloquent * * @author Murat Ödünç <[email protected]> * @copyright (c) 2015, Murat Ödünç * @license http://www.gnu.org/licenses/gpl-3.0.html GPLv3 * @package Repository */ abstract class EloquentRepository { /** * Eloquent Model * * @var \Illuminate\Database\Eloquent\Model */ protected $model; /** * current model * * @var \Illuminate\Database\Eloquent\Model */ protected $current; /** * Constructer */ public function __construct($model = null) { $this->model = $model; } /** * to get all users in a collection object * * @return \Illuminate\Database\Eloquent\Collection */ public function all() { return $this->model->all(); } /** * to get model by id * * @param int $id * @return Illuminate\Database\Eloquent\Model|null */ public function getById($id) { return $this->model->find($id); } /** * To create model * * @param array $attributes * @return bool */ abstract public function create(array $attributes); /** * To update model * * @param int $id * @param array $attributes * @return boolean */ abstract public function update($id, array $attributes); /** * to detete model * * @param int $id * @return bool */ public function delete($id) { $this->current = $this->getById($id); return is_null($this->current) ? false : $this->current->delete(); } /** * To get all users in Collection object * * @return \Illuminate\Database\Eloquent\Collection */ public function getModels() { return $this->all(); } /** * to get Instance * * @return \Illuminate\Database\Eloquent\Model */ public function getCurrent() { return $this->current; } }