1
votes

I have a single.blade.php file that shows a congress details and has also a form so the user can select the quantity of tickets that he wants for each ticket type.

When user selects the quantities and click next the request goes to the RegistrationController that has the storeQuantity() method to stores the selected quantities by the user in the array $selectedTypes, also returns an array "$customQuestions" and redirects the user to the registration.blade.php with the $selectedTypes array:

RegistrationController:

public function storeQuantity(Request $request, $id){
    $typeQuantities = $request->get('types');

    $customQuestions = Question::where('congress_id', $id);

    foreach($typeQuantities as $typeName => $quantity){

    $type = TicketType::where('name', $typeName)->firstOrFail();
    $price = $type->price;

    $selectedTypes[$type->name]['quantity'] = $quantity;
    $selectedTypes[$type->name]['price'] = $price;
    }
    return view('congresses.registration')->with('selectedTypes', $selectedTypes)->with('customQuestions', $customQuestions);
}

In the registration.blade.php I want to show the custom questions associated with each ticket type. I have the code below with "{{$customQuestion->question}}", but the question is not appearing.

Do you know where is the issue?

Registration.blade.php:

@if (!empty($allParticipants))
    @if($allParticipants == 1)
        @foreach($selectedTypes as $k=>$selectedType)
            <h6>Participant - 1 - {{$k}}</h6>
            <div class="form-group font-size-sm">
                <label for="name" class="text-gray">Name</label>
                <input type="text" class="form-control" id="name" value="">
            </div>
            <div class="form-group font-size-sm">
                <label for="surname" class="text-gray">Surname</label>
                <input type="text" class="form-control" name="surname" id="surname" value="">
            </div>

            @if (!empty($customQuestions))
                @if(count($customQuestions) > 0)
                    @foreach($customQuestions as $customQuestion)
                        <div class="form-group font-size-sm">
                            <label for="surname" class="text-gray">{{$customQuestion->question}}</label>
                            <input type="text" class="form-control" name="" id="" value="">
                        </div>
                    @endforeach
                @endif
            @endif
        @endforeach
    @endif
@endif

For example, the organizer of the congress with id "1" may have created for the ticket type "full access" the custom question "What is your email?". So in the foreach when the ticket type is "full access" it should appear, besides the name and surname, the field "what is your email.

I have this table content and relationships:

questions table:
id      question                congress_id
1       whats your email             1

ticket_type_questions table:
id        ticket_type_id      question_id
1            1                     1      (the ticket type 1 has the question 1)

ticket types table
id             name        congress_id
1             full access         1
2             basic               1

Note: Maybe the issue is because in "$customQuestions = Question::where('congress_id', $id); " it gets the questions associated with the congress. But each ticket type has associated questions and what is necessary is to show the questions associated with each ticket type not the questios associated with the congress.

1

1 Answers

1
votes

It looks to me like you are passing customeQuestions with an s in the controller and using customQuestion without in the view. That could cause your problem.

You also may need to add

$customQuestions = Question::where('congress_id', $id)->get();