Skip to content

Commit 00f0327

Browse files
committed
Add validation rules to blocks
1 parent 980a720 commit 00f0327

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app/Http/Controllers/UserController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,20 @@ public function saveLink(Request $request)
211211
$linkTypePath = base_path("blocks/{$linkType->typename}/handler.php");
212212
if (file_exists($linkTypePath)) {
213213
include $linkTypePath;
214-
$linkData = handleLinkType($request, $linkType);
214+
$result = handleLinkType($request, $linkType);
215+
216+
// Extract rules and linkData from the result
217+
$rules = $result['rules'];
218+
$linkData = $result['linkData'];
219+
220+
// Validate the request
221+
$validator = Validator::make($request->all(), $rules);
222+
223+
// Check if validation fails
224+
if ($validator->fails()) {
225+
return back()->withErrors($validator)->withInput();
226+
}
227+
215228
$linkData['button_id'] = $linkData['button_id'] ?? 1; // Set 'button_id' unless overwritten by handleLinkType
216229
$linkData['type'] = $linkType->typename; // Ensure 'type' is included in $linkData
217230
} else {

0 commit comments

Comments
 (0)