for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace IanOlson\Support\Services;
use Illuminate\Support\Facades\Lang;
use IanOlson\Support\Traits\ServiceTrait;
use IanOlson\Support\Traits\UpdateTrait;
use IanOlson\Support\Traits\ValidateTrait;
abstract class CrudServiceBase
{
use ServiceTrait;
use UpdateTrait;
use ValidateTrait;
/**
* Construct.
*
* @param null $model
*/
public function __construct($model = null)
if (isset($model)) {
$this->setModel($model);
}
* {@inheritDoc}
public function index()
return $this->createModel()->newQuery()->get();
public function create(array $data = [])
$this->validate($data);
$model = $this->createModel();
$this->updateAttributes($model, $data);
$model->save();
return $model;
public function read($id)
return $this->createModel()->newQuery()->where('id', $id)->first();
public function update($id, array $data = [])
if (!$model = $this->read($id)) {
$this->throwException(Lang::get('support.exceptions.model.read'));
public function delete($id)
$model->delete();
return true;