【问题标题】:Show the custom fields of each ticket type is not working (the custom field dont appears)显示每种工单类型的自定义字段不起作用(自定义字段不出现)
【发布时间】:2018-04-10 20:07:52
【问题描述】:

我有一个 single.blade.php 文件,其中显示了大会详细信息,还有一个表格,以便用户可以为每种票证类型选择他想要的票证数量。

当用户选择数量并单击下一步时,请求将转到具有 storeQuantity() 方法的 RegistrationController,以将用户选择的数量存储在数组 $selectedTypes 中,还返回一个数组“$customQuestions”并重定向用户使用 $selectedTypes 数组到registration.blade.php:

注册控制器:

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);
}

在registration.blade.php 中,我想显示与每种票证类型相关的自定义问题。我有下面的代码和“{{$customQuestion->question}}”,但问题没有出现。

你知道问题出在哪里吗?

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

例如,ID 为“1”的大会组织者可能为工单类型“完全访问”创建了自定义问题“您的电子邮件是什么?”。因此,在 foreach 中,当票证类型为“完全访问”时,除了姓名和姓氏之外,它应该出现“你的电子邮件是什么”字段。

我有这个表格内容和关系:

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

注意: 问题可能是因为在 "$customQuestions = Question::where('congress_id', $id); "中获取了与大会相关的问题。但是每个工单类型都有相关的问题,需要显示与每个工单类型相关的问题,而不是与大会相关的问题。

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    在我看来,您在控制器中传递 customeQuestionss 并在视图中使用 customQuestion。这可能会导致您的问题。

    您可能还需要添加

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 2011-02-14
      • 1970-01-01
      • 2011-05-20
      • 2021-11-26
      • 1970-01-01
      • 2017-05-05
      相关资源
      最近更新 更多