我做了一个main方法,它调用验证方法来检查一切是否正确。但是当验证方法发现问题并想要返回错误并将其显示给用户时,main方法将继续使用其余代码。你怎么能防止这种情况发生?这是我目前的代码:
public function postUpdateSettings(Request $request)
{
$this->validateSettings($request);
$this->updateSettings($request);
return redirect()->back()->with('succes', 'Your settings has been changed!');
}
private function validateSettings(Request $request)
{
$this->validate($request, [
'email' => 'required|string|email|max:255|unique:users,email,'.Auth::user()->id.'',
'first_name' => 'required|string|max:50|alpha',
'insertion' => 'nullable|max:25|alpha_spaces',
'last_name' => 'required|string|max:50|alpha',
'job' => 'required',
'message' => 'nullable|max:500',
]);
$jobs = $this->getJob();
if(in_array($request->input('job'), $jobs) === false){
return redirect()->route('home');
}
}