Skip to content

Commit

Permalink
Pulled slack validation out of setting model validation so it doesn’t…
Browse files Browse the repository at this point in the history
… fail mysteriously on other pages
  • Loading branch information
snipe committed Apr 8, 2020
1 parent 9269578 commit 206bd67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 14 additions & 4 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,24 @@ public function postSlack(Request $request)
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
}

$setting->slack_endpoint = $request->input('slack_endpoint');
$setting->slack_channel = $request->input('slack_channel');
$setting->slack_botname = $request->input('slack_botname');
$validatedData = $request->validate([
'slack_endpoint' => 'url|required_with:slack_channel|nullable',
'slack_channel' => 'regex:/(?<!\w)#\w+/|required_with:slack_endpoint|nullable',
'slack_botname' => 'string|nullable',
]);

if ($setting->save()) {
if ($validatedData) {

$setting->slack_endpoint = $request->input('slack_endpoint');
$setting->slack_channel = $request->input('slack_channel');
$setting->slack_botname = $request->input('slack_botname');

$setting->save();
return redirect()->route('settings.index')
->with('success', trans('admin/settings/message.update.success'));

}

return redirect()->back()->withInput()->withErrors($setting->getErrors());

}
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Setting extends Model
'admin_cc_email' => 'email|nullable',
'default_currency' => 'required',
'locale' => 'required',
'slack_endpoint' => 'url|required_with:slack_channel|nullable',
'slack_channel' => 'regex:/(?<!\w)#\w+/|required_with:slack_endpoint|nullable',
'slack_botname' => 'string|nullable',
'labels_per_page' => 'numeric|min:1',
'labels_width' => 'numeric',
'labels_height' => 'numeric',
Expand Down

0 comments on commit 206bd67

Please sign in to comment.