简体   繁体   English

“此集合实例上不存在属性[registration_types]。”

[英]“Property [registration_types] does not exist on this collection instance.”

I have this code to show the next registrations of a user in a conference: 我有以下代码来显示用户在会议中的下一个注册:

$nextRegistrations = $user->registrations()
          ->with('participants.registration_type')
          ->whereHas(
              'conference',
              function ($query) {
                  $query->where('end_date', '>', now());
              }
          )->paginate($pageLimit);

In the view I want to show a link "Get certificate" if the column "available_certificate" of the "registration_types" table has the value "Y". 在视图中,如果“ registration_types”表的“ available_certificate”列的值为“ Y”,我想显示链接“获取证书”。

But with the code below is not working, it appears "Property [registration_types] does not exist on this collection instance." 但是,由于下面的代码不起作用,因此显示“此集合实例上不存在属性[registration_types]”。

@foreach($nextRegistrations as $nextRegistration)

@if ($nextRegistration->participants->registration_types->certificate_available == 'Y')
    <a href="{{route('conferences.registrationInfo',['regID'=> $nextRegistration->id])}}"class="btn btn-primary">Get Certificate</a>
@endif
@endforeach

For example if there is only 1 next registration $nextRegistrations shows: 例如,如果下一个注册只有1个,则$ nextRegistrations显示:

LengthAwarePaginator {#325 ▼
  ...
  #items: Collection {#319 ▼
    #items: array:1 [▼
      0 => Registration {#320 ▼
      ...
        #relations: array:1 [▼
          "participants" => Collection {#307 ▼
            #items: array:1 [▼
              0 => Participant {#321 ▼
                ...
                #relations: array:1 [▼
                  "registration_type" => RegistrationType {#326 ▶}
                ]
                ...
              }
            ]
          }
        ]
        ...
      }
    ]
  }
 ...
}

Code in the view: 视图中的代码:

<ul class="list-group events-list">
    @foreach($nextRegistrations as $nextRegistration)
        @if(!empty($nextRegistration->conference) || !empty($nextRegistration->conference->date))
            <li class="list-group-item">
                <p>{{optional($nextRegistration->conference)->date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                <h5>{{optional($nextRegistration->conference)->name}}</h5>
                <p> Registration {{$nextRegistration->created_at }}
                </p>
                @if ($nextRegistration->invoice == 'Y')
                  <!-- show some content -->
                @endif

                @if ($nextRegistration->totalPrice <= 0)
                    <!-- show some content -->
                @endif

                @if ($nextRegistration->status == 'C')
                   <!-- show some content -->
                @endif

                @if ($nextRegistration->status === 'I')
                    <!-- show some content -->
                @endif

            </li>
        @endif
    @endforeach
</ul>

Change 更改

@foreach($nextRegistrations as $nextRegistration)
    @foreach($nextRegistration->participants as $participant)
        @if ($participant->registration_type->certificate_available == 'Y')
            <a href="{{route('conferences.registrationInfo',['regID'=> $nextRegistration->id])}}"class="btn btn-primary">Get Certificate</a>
        @endif
    @endforeach
@endforeach

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “此集合实例上不存在属性 [角色]。” - "Property [role] does not exist on this collection instance." 该集合实例上不存在属性[title]。 拉拉韦尔5.5 - Property [title] does not exist on this collection instance. laravel 5.5 (1/1)异常属性[price]在该集合实例上不存在。 (Laravel 5.4) - (1/1) Exception Property [price] does not exist on this collection instance. (Laravel 5.4) 此集合实例上不存在属性 [expiry_date]。 在 Laravel - Property [expiry_date] does not exist on this collection instance. in Laravel 此集合实例上不存在属性 [图像]。 / Laravel - with() 方法 - Property [image] does not exist on this collection instance. / Laravel - with() Method 该集合实例上不存在属性[associated_occupation]。 -Laravel - Property [associated_occupation] does not exist on this collection instance. - Laravel 此集合实例上不存在属性 [vegan]。 Laravel - Property [vegan] does not exist on this collection instance. Laravel 此集合实例上不存在属性 [ID]。 Laravel 表格错误 - Property [ID] does not exist on this collection instance. Laravel Form error 该集合实例上不存在属性[date]。 当我调用API - Property [date] does not exist on this collection instance. When i call the API Laravel错误:此集合实例上不存在属性[id]。 但是它可以在本地服务器上运行 - Laravel Error: Property [id] does not exist on this collection instance. Yet it works on the local server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM