Last active
May 4, 2017 09:02
-
-
Save danjohnson95/606f8dbb100c3d0dbb6b1c1407487591 to your computer and use it in GitHub Desktop.
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 characters
<?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