Skip to content

Commit

Permalink
feat(service): create CRUD methods
Browse files Browse the repository at this point in the history
  • Loading branch information
txsoura committed May 9, 2021
1 parent 6662d4a commit 2bf687a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Services/Traits/CRUDMethodsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Txsoura\Core\Services\Traits;

use Txsoura\Core\Http\Requests\QueryParamsRequest;

trait CRUDMethodsService
{
protected $queryParamsRequest = QueryParamsRequest::class;

public function index()
{
$this->request = resolve($this->queryParamsRequest);

return $this->repository->setRequest($this->request)->all();
}

public function store()
{
$this->request = resolve($this->storeRequest);

return $this->model()::create($this->request->validated());
}

public function show($id)
{
$this->request = resolve($this->queryParamsRequest);

return $this->repository->setRequest($this->request)->findOrFail($id);
}

public function update($id)
{
$this->request = resolve($this->updateRequest);

$model = $this->repository->findOrFail($id);
$model->update($this->request->validated());
return $model;
}

public function destroy($id)
{
$model = $this->model()::findOrFail($id);
$model->delete();
}
}

0 comments on commit 2bf687a

Please sign in to comment.