Created
March 8, 2018 00:32
-
-
Save jsdecena/7e55ab097ed675a3718d1e0c824da6c3 to your computer and use it in GitHub Desktop.
Carousel Repository Class
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\Shop\Carousels\Repositories; | |
use App\Shop\Carousels\Carousel; | |
use App\Shop\Carousels\Exceptions\CarouselNotFoundException; | |
use App\Shop\Carousels\Exceptions\CreateCarouselErrorException; | |
use Illuminate\Database\Eloquent\ModelNotFoundException; | |
use Illuminate\Database\QueryException; | |
class CarouselRepository | |
{ | |
protected $model; | |
/** | |
* CarouselRepository constructor. | |
* @param Carousel $carousel | |
*/ | |
public function __construct(Carousel $carousel) | |
{ | |
$this->model = $carousel; | |
} | |
/** | |
* @param array $data | |
* @return Carousel | |
* @throws CreateCarouselErrorException | |
*/ | |
public function createCarousel(array $data) : Carousel | |
{ | |
try { | |
return $this->model->create($data); | |
} catch (QueryException $e) { | |
throw new CreateCarouselErrorException($e); | |
} | |
} | |
/** | |
* @param int $id | |
* @return Carousel | |
* @throws CarouselNotFoundException | |
*/ | |
public function findCarousel(int $id) : Carousel | |
{ | |
try { | |
return $this->model->findOrFail($id); | |
} catch (ModelNotFoundException $e) { | |
throw new CarouselNotFoundException($e); | |
} | |
} | |
/** | |
* @param array $data | |
* @return bool | |
* @throws UpdateCarouselErrorException | |
*/ | |
public function updateCarousel(array $data) : bool | |
{ | |
try { | |
return $this->model->update($data); | |
} catch (QueryException $e) { | |
throw new UpdateCarouselErrorException($e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment