Skip to content

Commit

Permalink
wip on validations publish action
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 16, 2023
1 parent c1ab56f commit 87ec7ce
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
35 changes: 21 additions & 14 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,27 @@ public function changeStatus($id, Request $request)
$project = Project::findOrFail($id);
$projectArray = $project->toArray();
$project['preview'] = $project->getFirstMediaUrl('preview') ?? null;

Validator::make($projectArray, [
'name' => ['required', 'max:255'],
'start' => ['required', 'date', 'after_or_equal:today'],
'end' => ['required', 'date', 'after:start'],
'target_amount' => ['required', 'numeric', 'min:1'],
'categories' => ['required', 'array', 'min:1'],
'counties' => ['required_if:is_national,0', 'array', 'min:1'],
'description' => ['required', 'min:100', 'max:1000'],
'scope' => ['required', 'min:100', 'max:1000'],
'beneficiaries' => ['required', 'min:100', 'max:1000'],
'reason_to_donate' => ['required', 'min:100', 'max:1000'],
'preview' => ['required'],
])->validate();
// dd($project);

Validator::make(
$projectArray,
[
'name' => ['required', 'max:255'],
'start' => ['required', 'date', 'after_or_equal:tomorrow'],
'end' => ['required', 'date', 'after:start'],
'target_budget' => ['required', 'numeric', 'min:1'],
'categories' => ['required', 'array', 'min:1'],
'counties' => ['required_if:is_national,0', 'array', 'min:1'],
'description' => ['required', 'min:100', 'max:1000'],
'scope' => ['required', 'min:100', 'max:1000'],
'beneficiaries' => ['required', 'min:100', 'max:1000'],
'reason_to_donate' => ['required', 'min:100', 'max:1000'],
'preview' => ['required'],
],
[
'start.after_or_equal' => __('custom_validation.start_date.after_or_equal'),
]
)->validate();

try {
(new ProjectService(Project::class))->changeStatus($id, $request->get('status'));
Expand Down
3 changes: 3 additions & 0 deletions lang/ro/custom_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
return [
'activity_domains_ids' => 'Trebuie să selectați cel puțin un domeniu de activitate.',
'counties_ids' => 'Trebuie să selectați cel puțin un județ.',
'start_date' =>[
'after_or_equal' => 'Data de început nu poate fi in trecut.',
]
];
7 changes: 6 additions & 1 deletion lang/ro/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,10 @@
'user.email' => 'email',
'user.password' => 'parolă',
'end' => "Data finală perioada de donații",
'start' => "Data început perioada de donații",
'today' => "Data de azi",
'target_budget' => "Bugetul țintă",
'categories' => "Categorii",
'counties' => "Județe",
],
];
];
2 changes: 1 addition & 1 deletion resources/js/Pages/AdminOng/Projects/EditProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</Field>

<!-- Edit target amount -->
<Field :label="$t('amount_target_label')" :hasPendingChanges="changes.includes('target_budget')" :errors="formChangeStatus.errors.target_amount">
<Field :label="$t('amount_target_label')" :hasPendingChanges="changes.includes('target_budget')" :errors="formChangeStatus.errors.target_budget">
<template #value>
{{ project.target_budget }}
</template>
Expand Down

0 comments on commit 87ec7ce

Please sign in to comment.