Skip to content

Commit

Permalink
refactor(admin): validation rules in PostsController
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq1988 committed Mar 19, 2024
1 parent 17ef441 commit ec8250d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions app/Http/Controllers/Admin/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ class PostsController extends Controller
{
public function store(Request $request)
{
$request->validate([
$rules = [
'title' => 'required',
'body' => 'required',
'status_id' => 'required|exists:statuses,id',
'board_id' => 'required|exists:boards,id',
'behalf_id' => 'sometimes|exists:users,id',
]);
];

if ($request->has('behalf_id') && $request->behalf_id) {
$rules['behalf_id'] = 'exists:users,id';
}

$request->validate($rules);

$args = [
'title' => $request->title,
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/Admin/Feedbacks/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CreateModal = ({
body: '',
board_id: '',
status_id: '',
behalf_id: 0,
behalf_id: null,
});

const statusOptions = statuses.map((status) => ({
Expand Down Expand Up @@ -92,7 +92,7 @@ const CreateModal = ({
setBehalfUser(user);
form.setData('behalf_id', user.id);
}}
onClear={() => form.setData('behalf_id', 0)}
onClear={() => form.setData('behalf_id', null)}
/>
</div>

Expand Down

0 comments on commit ec8250d

Please sign in to comment.