Skip to content

Instantly share code, notes, and snippets.

@jsdecena
Created March 8, 2018 01:04
Show Gist options
  • Save jsdecena/ab8283f0f1140655b43ff722e003a109 to your computer and use it in GitHub Desktop.
Save jsdecena/ab8283f0f1140655b43ff722e003a109 to your computer and use it in GitHub Desktop.
Carousel Repository Find Carousel Method
<?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 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);
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment