From 87ec7ced739475b80377169642ecdd0fa15ba4a0 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Mon, 16 Oct 2023 11:34:09 +0300 Subject: [PATCH] wip on validations publish action --- .../Dashboard/ProjectController.php | 35 +++++++++++-------- lang/ro/custom_validation.php | 3 ++ lang/ro/validation.php | 7 +++- .../Pages/AdminOng/Projects/EditProject.vue | 2 +- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Dashboard/ProjectController.php b/app/Http/Controllers/Dashboard/ProjectController.php index f811be74..1a0ec49e 100644 --- a/app/Http/Controllers/Dashboard/ProjectController.php +++ b/app/Http/Controllers/Dashboard/ProjectController.php @@ -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')); diff --git a/lang/ro/custom_validation.php b/lang/ro/custom_validation.php index 1180d584..86713512 100644 --- a/lang/ro/custom_validation.php +++ b/lang/ro/custom_validation.php @@ -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.', + ] ]; diff --git a/lang/ro/validation.php b/lang/ro/validation.php index 1de3baef..59a5326d 100644 --- a/lang/ro/validation.php +++ b/lang/ro/validation.php @@ -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", ], -]; \ No newline at end of file +]; diff --git a/resources/js/Pages/AdminOng/Projects/EditProject.vue b/resources/js/Pages/AdminOng/Projects/EditProject.vue index 908d430c..75f2b5fb 100644 --- a/resources/js/Pages/AdminOng/Projects/EditProject.vue +++ b/resources/js/Pages/AdminOng/Projects/EditProject.vue @@ -29,7 +29,7 @@ - +