I have a context where a conference can have 1 or more registration types and the user can do a registration in a conference in 1 or more registration types of the conference.
So for example, I have a conference stored in DB that has two registration types associated with it, the registration rype "general" and "plus". The registration type "general" has 2 custom questions associated with it, the registration type "plus" dont have any custom question associated with it.
When a user is doing a registration in a conference and select, for example, quantity "2" for the registration type "plus" and click "Next" the user goes to the registration page. In this page there is the registration form and the user only needs to enter his name and surname and click "Register". The $request->all shows like below, the participants array stores the name, surname and registration type of each participant:
array:4 [▼
"participant" => array:2 [▼
1 => array:3 [▼
"name" => "John"
"surname" => "W"
"rtypes" => "2"
]
2 => array:3 [▼
"name" => "Jake"
"surname" => "K"
"rtypes" => "2"
]
]
]
RegistrationController storeRegistration() to store the registration details:
public function storeRegistration(Request $request, $id, $slug = null)
{
# user object
$user = Auth::user();
# add registration to Database
$registration = Registration::create([
'conference_id' => $id,
'user_that_did_registration' => $user->id,
]);
# List of all participants
$participants_list = $request->get('participant');
#add all participants to Database
foreach ($participants_list as $participant) {
$name = $participant['name'];
$surname = $participant['surname'];
$participant_result = Participant::create([
'name' => $name,
'surname' => $surname,
'registration_id' => $registration->id,
'registration_type_id' => $participant['rtypes']
]);
# save answer to Database if exist
if (isset($participant['question_id'])) {
$answer = Answer::create([
'question_id' => $participant['question_id'],
'participant_id' => $participant_result->id,
'answer' => $participant['answer'],
]);
}
}
Session::flash('registration_success', 'You are registered');
return redirect(route('user.index', ['user' => Auth::id()]) . '#myTickets');
}
And it works fine, all info is correctly stored in the array and then is possible to store all the necessary info in DB.
Doubt: when there are custom questions associated with the registration type selected by the user how to store the answers??
If the user is doing a registration and select quantity "2" for the registration type "general" and click "Next", the registration type "general" has 2 custom questions associated with it. So in the registration form the user needs to enter his name and surname but the user also needs to answer the 2 required custom questions. My doubt is how to store for each participant the answers to the custom questions, do you know how to properly achieve that? Like below only stores the name, surname and the registration type where the participant is being registered.
But how to store also the answers to each question?
array:4 [▼
"participant" => array:2 [▼
1 => array:3 [▼
"name" => "John"
"surname" => "W"
"rtypes" => "1"
]
2 => array:3 [▼
"name" => "Jake"
"surname" => "K"
"rtypes" => "1"
]
]
]
Registration Form:
<form method="post"
action="https://proj.test/conference/1/conference-test/registration/storeRegistration">
<h6>Participant - 1 - general</h6>
<div class="form-group font-size-sm">
<label for="namegeneral_1"
class="text-gray">Name</label>
<input type="text" required id="namegeneral_1"
name="participant[name]"
class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="surnamegeneral_1"
class="text-gray">Surname</label>
<input type="text" required id="surnamegeneral_1"
class="form-control"
name="participant[surname]" value="">
</div>
<div class="form-group">
<label for="participant_question">Input text custom question</label>
<input type='text' name='participant[1][answer]' class='form-control' required>
<input type="hidden"
name="participant_question_required[]"
value="1">
<input type="hidden"
value="1"
name="participant[1][question_id]"/>
</div>
<div class="form-group">
<label for="participant_question">Long text custom question</label>
<textarea name='participant[1][answer]' class='form-control' rows='3' required></textarea>
<input type="hidden"
name="participant_question_required[]"
value="1">
<input type="hidden"
value="2"
name="participant[1][question_id]"/>
</div>
<input type="hidden" name="participant[1][rtypes]" value="1"/>
<h6>Participant - 2 - general</h6>
<div class="form-group font-size-sm">
<label for="namegeneral_2"
class="text-gray">Name</label>
<input type="text" required id="namegeneral_2"
name="participant[name]"
class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="surnamegeneral_2"
class="text-gray">Surname</label>
<input type="text" required id="surnamegeneral_2"
class="form-control"
name="participant[surname]" value="">
</div>
<div class="form-group">
<label for="participant_question">Input type text custom question</label>
<input type='text' name='participant[2][answer]' class='form-control' required>
<input type="hidden"
name="participant_question_required[]"
value="1">
<input type="hidden"
value="1"
name="participant[2][question_id]"/>
</div>
<div class="form-group">
<label for="participant_question">Long text custom question</label>
<textarea name='participant[2][answer]' class='form-control' rows='3' required></textarea>
<input type="hidden"
name="participant_question_required[]"
value="1">
<input type="hidden"
value="2"
name="participant[2][question_id]"/>
</div>
<input type="hidden" name="participant[2][rtypes]" value="1"/>
<input type="submit" class="btn btn-primary" value="Register"/>
</form>
Images to explain better the context:
This image shows the registration form, in this case the registration type general has only 1 custom question associated (Phone), so this question will appear twice because it was selected "2" for the registration type "general": https://ibb.co/f3Y3vz
This image shows how the database should stay based on the registration form image above: https://ibb.co/jXgTTK
One thing will have numerous labels. Also, one tag will have a place with numerous things. This infers to me that you'll perhaps require a delegate table to conquer the many-to-numerous deterrent.
Something like:
Table: Items
Columns: Item_ID, Item_Title, Content
Table: Tags
Columns: Tag_ID, Tag_Title
Table: Items_Tags
Columns: Item_ID, Tag_ID
It may be that your web application is madly prominent and require denormalising not far off, however it's futile muddying the waters too soon.
By:Xtreem Solution
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community