Skip to content

Commit

Permalink
adds validation rules for label names
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Jan 14, 2025
1 parent dd08642 commit 69d255f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/Http/Requests/StoreLabelSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -22,6 +25,10 @@ public function authorize(): bool
*/
public function rules(): array
{
$names = Label::find()?->map(function ($label) {
return $label->getName();
})->values()->toArray();

return [
'labels_per_page' => 'numeric',
'labels_width' => 'numeric',
Expand All @@ -36,7 +43,10 @@ public function rules(): array
'labels_pagewidth' => 'numeric|nullable',
'labels_pageheight' => 'numeric|nullable',
'qr_text' => 'max:31|nullable',
'label2_template' => 'required|string',
'label2_template' => [
'required',
Rule::in($names),
],
];
}
}

0 comments on commit 69d255f

Please sign in to comment.