[form-builder] In form builder can we send error response and exit form?
Created 7 years ago by lckamalI am trying like this for exit form and send response
class UserLanguageFormBuilder extends FormBuilder
{
...
public function onPost()
{
$language = \Request::get('language');
$userlang = UserLanguageModel::where(['user_id' => auth()->id(), 'language_id' => $language])->count();
if($userlang > 0){
return response()->json(['success' => false, 'message' => 'This language is already added.']);
}
}
}
Is there some other options instead?
piterden
—
7 years ago
Link
dali
—
7 years ago
instead of using onPost create a handler class UserLanguageFormHandler
and :
public function handle(UserLanguageFormBuilder $builder, MessageBag $messages, Redirector $redirect)
{
$messages->error('Cant save now..');
$builder->setSave(false);
$builder->setFormResponse($redirect->back());
}