From 69d255f584bee46f147c4d74f99fd7ab51e70a41 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 14 Jan 2025 12:07:59 -0800 Subject: [PATCH] adds validation rules for label names --- app/Http/Requests/StoreLabelSettings.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/StoreLabelSettings.php b/app/Http/Requests/StoreLabelSettings.php index e11ead8baf..6a39418a67 100644 --- a/app/Http/Requests/StoreLabelSettings.php +++ b/app/Http/Requests/StoreLabelSettings.php @@ -2,8 +2,11 @@ namespace App\Http\Requests; + +use App\Models\Labels\Label; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Gate; +use Illuminate\Validation\Rule; class StoreLabelSettings extends FormRequest { @@ -22,6 +25,10 @@ class StoreLabelSettings extends FormRequest */ public function rules(): array { + $names = Label::find()?->map(function ($label) { + return $label->getName(); + })->values()->toArray(); + return [ 'labels_per_page' => 'numeric', 'labels_width' => 'numeric', @@ -36,7 +43,10 @@ class StoreLabelSettings extends FormRequest 'labels_pagewidth' => 'numeric|nullable', 'labels_pageheight' => 'numeric|nullable', 'qr_text' => 'max:31|nullable', - 'label2_template' => 'required|string', + 'label2_template' => [ + 'required', + Rule::in($names), + ], ]; } }