Files
cachet-docker/app/CachetHQ/Cachet/Repositories/Incident/EloquentIncidentRepository.php
T
James Brooks 655042da3c Fixes #158
2014-12-31 15:36:11 +00:00

47 lines
1.0 KiB
PHP

<?php
namespace CachetHQ\Cachet\Repositories\Incident;
use CachetHQ\Cachet\Repositories\EloquentRepository;
use Incident;
class EloquentIncidentRepository extends EloquentRepository implements IncidentRepository
{
protected $model;
public function __construct(Incident $model)
{
$this->model = $model;
}
public function create($user_id, array $array)
{
$incident = new $this->model($array);
$incident->user_id = $user_id;
$this->validate($incident);
if (isset($array['component_id'])) {
$this->hasRelationship($incident, 'component');
}
$incident->saveOrFail();
return $incident;
}
public function update($id, array $array)
{
$incident = $this->model->findOrFail($id);
$incident->fill($array);
$this->validate($incident);
if (isset($array['component_id'])) {
$this->hasRelationship($incident, 'component');
}
$incident->update($array);
return $incident;
}
}