In my Laravel application I have a sign up process in which users must select a category they fall under, each category is in it's own form.
In each of these forms there are a set of checkboxes and users must tick at least one, otherwise validation should fail, I've been doing some reading and found two great, similar questions:
Handling multiple forms on a single page
Laravel request validation with multiple forms on the same page
At the moment I'm feeding all 3 forms to the same method:
/**
* Store a user's selected investor type and progress onto next stage
*
* @param Request $request
* @return void
*/
public function storeInvestorType(Request $request)
{
$user = auth()->user();
$user->investor_type = $request->get('investor_type');
$user->declaration_date = Carbon::now();
$user->save();
Log::info("{$user->log_reference} has declared that they are a '{$user->investor_type}' investor.");
return redirect()->route('user.member-type');
}
Which literally just updates a column in a database.
Would it be cleaner to have 3 separate methods or just to name each form?
An update
I have added a name="something"
to each submit button so that I can do something like this in the controller:
/**
* Store a user's selected investor type and progress onto next stage
*
* @param Request $request
* @return void
*/
public function storeInvestorType(Request $request)
{
$user = auth()->user();
if ($request->has('high_net_worth')){
if(!$request->has('high_net_worth_criteria')){
return redirect()->back()->withErrors('Please tick at least one criteria that specifies you are a High Net Worth investor');
} else{
$investor_type = "High Net Worth";
}
} elseif ($request->has('self_certified_sophisticated')) {
if (!$request->has('self_certified_sophisticated_criteria')) {
return redirect()->back()->withErrors('Please tick at least one criteria that specifies you are a Self-Certified Sophisticated investor');
} else {
$investor_type = "Self-Certified Sophisticated";
}
} elseif ($request->has('other')) {
$investor_type = "Other";
}
$user->investor_type = $investor_type;
$user->declaration_date = Carbon::now();
$user->save();
Log::info("{$user->log_reference} has declared that they are a '{$user->investor_type}' investor.");
return redirect()->route('user.member-type');
}