Skip to content

Commit ce9c673

Browse files
fix: null user input post and put method
1 parent ba273ce commit ce9c673

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Controller/AbstractController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use RestJS\Message\Response;
66
use function RestJS\response, RestJS\checkNull;
7+
use Slim\Exception\HttpBadRequestException;
78

89
/** Abstract Controller Functions */
910
class AbstractController {
@@ -23,7 +24,6 @@ public function findAll($req, $res) {
2324
/** Find Data by Column */
2425
public function findByColumn($req, $res, $args) {
2526
$data = $this->_model->findBy($args);
26-
checkNull($data, $req);
2727
return response($req, $res, args: new Response(data: [...$data]));
2828
}
2929

@@ -36,12 +36,18 @@ public function delete($req, $res, $args) {
3636

3737
/** Insert Data */
3838
public function insert($req, $res, $args) {
39-
$data = $this->_model->insert([...$req->getParsedBody(), ...$args ]);
39+
if (!$req->getParsedBody())
40+
throw new HttpBadRequestException($req, "Please enter valid form data.");
41+
42+
$data = $this->_model->insert([...$req->getParsedBody(), ...$args]);
4043
return response($req, $res, new Response(message: "This item has been successfully added.", data: $data));
4144
}
4245

4346
/** Update by Id */
4447
public function update($req, $res, $args) {
48+
if (!$req->getParsedBody())
49+
throw new HttpBadRequestException($req, "Please enter valid form data.");
50+
4551
$data = $this->_model->update($req->getParsedBody(), $args);
4652
checkNull($data, $req);
4753
return response($req, $res, new Response(message: "This item has been successfully updated.", data: $data));

0 commit comments

Comments
 (0)