Created
March 25, 2014 21:06
-
-
Save vinicius73/9771385 to your computer and use it in GitHub Desktop.
Modelo de Repository [LARAVEL]
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 MyApp\Repository; | |
use MyApp\Category; | |
class CategoryRepository | |
{ | |
/** | |
* @return \Illuminate\Database\Eloquent\Collection|static[] | |
*/ | |
public function all(){} | |
/** | |
* @param int $id | |
* @param bool $fail | |
* | |
* @return Category | |
*/ | |
public function find($id, $fail = TRUE) | |
{ | |
if ($fail) { | |
return Category::findOrFail($id); | |
} | |
return Category::find($id); | |
} | |
/** | |
* @param Category $category | |
* @param array $data | |
* | |
* @return bool | |
*/ | |
public function update(Category &$category, $data = array()) | |
{ | |
if (empty($data)) { | |
$category->fill(Input::except('_method')); | |
} else { | |
$category->fill($data); | |
} | |
return $this->save($category); | |
} | |
/** | |
* @param Category $category | |
* @param array $rules | |
* | |
* @return bool | |
*/ | |
public function save(Category &$category, $rules = array()) | |
{ | |
if (empty($rules)) { | |
return $category->save(); | |
} | |
return $category->save($rules); | |
} | |
/** | |
* @param array $data | |
* | |
* @return Category | |
*/ | |
public function create($data = array()) | |
{ | |
$category = new Category(); | |
if (empty($data)) { | |
$category->fill(Input::except('_method')); | |
} else { | |
$category->fill($data); | |
} | |
return $category; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment