Skip to content

Instantly share code, notes, and snippets.

@danjohnson95
Last active May 4, 2017 09:02
Show Gist options
  • Save danjohnson95/606f8dbb100c3d0dbb6b1c1407487591 to your computer and use it in GitHub Desktop.
Save danjohnson95/606f8dbb100c3d0dbb6b1c1407487591 to your computer and use it in GitHub Desktop.
<?php namespace App\Repos;
use App\Contracts\ProductDataInterface;
class ProductRepository
{
/**
* An instance of the Product model
* @var \App\Contracts\ProductDataInterface
*/
protected $data;
/**
* Injects the dependency
* @param \App\Contracts\ProductDataInterface $data
*/
public function __construct(ProductDataInterface $data)
{
$this->data = $data;
}
/**
* Finds a product by the ID
* @param int $id
* @return \Illuminate\Support\Collection
*/
public function findById($id)
{
return $this->data->find($id);
}
/**
* Returns a new blank model
* @return \App\Contracts\ProductDataInterface
*/
public function new()
{
return new $this->data;
}
/**
* Saves the model passed through
* @param \App\Contracts\ProductDataInterface $data
* @return bool
*/
public function save(ProductDataInterface $data)
{
return $data->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment