Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created March 25, 2014 21:06
Show Gist options
  • Save vinicius73/9771385 to your computer and use it in GitHub Desktop.
Save vinicius73/9771385 to your computer and use it in GitHub Desktop.
Modelo de Repository [LARAVEL]
<?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