Skip to content

Commit

Permalink
Moved to using Exists and Unique in scaffolding Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aymenBenadra committed May 15, 2022
1 parent 108ad42 commit a7cd262
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/Models/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Example extends Model
public function __construct()
{
parent::__construct([
'exampleField' => 'required|numeric|min:1|max:10|int|float|bool|array|object|email|file|image|url|date|date_format|same|matches|ip'
'exampleField' => 'required|numeric|min:1|max:10|int|float|bool|array|object|email|file|image|url|date|date_format|same|matches|ip|exists:table,field|unique:table,field|regex:pattern'
]);
$this->table = 'Examples';
}
Expand Down
31 changes: 1 addition & 30 deletions app/controllers/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,9 @@ public function index()
*/
public function show($data = [])
{
$example = $this->model->get($data['id']);

if ($example === false) {
Router::abort(404, json_encode([
'status' => 'error',
'message' => 'example not found'
]));
}

Response::send([
'status' => 'success',
'data' => $example
'data' => $this->model->get($data['id'])
]);
}

Expand Down Expand Up @@ -113,16 +104,6 @@ public function update($data = [])
$id = $data['id'];
unset($data['id']);

// check if example exists
$example = $this->model->get($id);

if (!$example) {
Router::abort(404, json_encode([
'status' => 'error',
'message' => 'example not found'
]));
}

if (!$this->model->update($id, $data)) {
Router::abort(500, json_encode([
'status' => 'error',
Expand All @@ -146,16 +127,6 @@ public function update($data = [])
*/
public function delete($data = [])
{
// check if example exists
$example = $this->model->get($data['id']);

if (!$example) {
Router::abort(404, json_encode([
'status' => 'error',
'message' => 'example not found'
]));
}

if (!$this->model->delete($data['id'])) {
Router::abort(500, json_encode([
'status' => 'error',
Expand Down

0 comments on commit a7cd262

Please sign in to comment.