drtsd7864 2018-07-24 20:08
浏览 134
已采纳

单击搜索按钮后,为什么会出现分页错误?

I have a page "https://proj.test/user/profile?user=2#myRegistrations" where I have two tabs, one tab show the past registrations of a user in conferences and other tab the next registrations of the user in a conference. The user can click "Past Registrations" to check the past registrations and click in "Next Registrations" to check his next registrations in conferences. And its working.

In this same page, above the tabs, I have a form for the user to search for a conference name where he his registered. But when the user enters some text in the form search input like "test" and click in "Search" it appears "Undefined property: Illuminate\Pagination\LengthAwarePaginator::$participants (View: /Users/john/projects/proj/resources/views/users/index.blade.php)". Do you know what can be the issue?

Code in he view:

<div class="tab-pane clearfix fade" id="myTickets" role="tabpanel" aria-labelledby="contact-tab">
    <div class="d-flex justify-content-between">

        <form method="get" class="clearfix  w-75" method="POST" action="{{ route('user.searchRegistration') }}">
            {{ csrf_field() }}
            <div class="form-group col col-md-6 px-0">
                <div class="input-group" data-provide="datepicker">
                    <input type='text' class="form-control" placeholder="Search Registrations"
                           name="search_registration"
                           value="{{old('search_registration')}}"/>
                    <button class="input-group-addon">Search</button>
                </div>
            </div>
        </form>
        <a href="{{route('user.cleanSearchRegistration')}}" class="btn btn-outline-primary"
           id="cleanSearchRegistration">Clean Search</a>
    </div>

    @if(session('searchedRegistrations'))
        @if(session('searchedRegistrations')->count() != null)
            @foreach(session('searchedRegistrations') as $registration)
                @foreach(session('searchedRegistrations')->participants as $participant)
                    @if(!empty($registration))
                        <li class="list-group-item">
                            <h5>{{optional($registration->conference)->name}}</h5>

                            @if ($registration->status == 'C')
                                <a href="{{route('conference.registrationInfo',
                                    ['id' => $registration->conference->id,
                                    'slug' => $registration->conference->slug,
                                    'regID'=> $registration->id])}}"
                                   class="btn btn-primary ml-2"><i class="fa fa-file-pdf-o"></i> Registration document
                                </a>
                            @endif
                            @if ($participant->registration_type->certificate_available == 'Y')
                                <a href="{{route('conferences.certificateInfo',
                                    [
                                    'regID'=> $registration->id])}}"
                                   class="btn btn-primary ml-2"><i class="fa fa-file-pdf-o"></i> Download certificate
                                </a>
                                @break
                            @endif
                        </li>
                    @endif
                @endforeach
            @endforeach
            <div class="text-center d-flex justify-content-center mt-3">
                {{session('searchedRegistrations')->fragment('searchRegistrations')->links("pagination::bootstrap-4")}}
            </div>
        @else
            <div class="alert alert-info" role="alert">
                <i class="material-icons">info</i>
                <span>Your search didnt return any result.</span>
            </div>
        @endif
    @else
        <div class="d-flex mb-3">
            <ul class="nav nav-pills">
                <li class="nav-item">
                    <a class="nav-link active border" href="#nextConferences" data-toggle="tab" role="tab">Next
                        Conferences</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link border" href="#PastRegistrations" data-toggle="tab" role="tab">Past
                        Conferences</a>
                </li>
            </ul>
        </div>

        <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active clearfix" id="nextConferences" role="tabpanel"
                 aria-labelledby="home-tab">

                <ul class="list-group">
                    @foreach($nextRegistrations as $nextRegistration)
                        @foreach($nextRegistration->participants as $participant)
                            @if(!empty($nextRegistration->conference) || !empty($nextRegistration->conference->start_date))
                                <li class="list-group-item">
                                    <h5>{{optional($nextRegistration->conference)->name}}</h5>

                                    @if ($participant->registration_type->certificate_available == 'Y')
                                        <a href="{{route('conferences.certificateInfo',
                                    [
                                    'regID'=> $nextRegistration->id])}}"
                                           class="btn btn-primary ml-2"><i
                                                    class="fa fa-file-pdf-o"></i> Download Certificate</a>
                                        @break
                                    @endif

                                    @if ($nextRegistration->status == 'C')
                                        <a href="{{route('conferences.registrationInfo',
                                    [
                                    'regID'=> $nextRegistration->id])}}"
                                           class="btn btn-primary ml-2"><i
                                                    class="fa fa-file-pdf-o"></i> Registration document
                                        </a>
                                    @endif
                                </li>
                            @endif
                        @endforeach
                    @endforeach
                </ul>
                <div class="text-center d-flex justify-content-center mt-3">
                    {{$nextRegistrations->fragment('nextConferences')->links("pagination::bootstrap-4")}}
                </div>
            </div>

            <div class="tab-pane fade show clearfix" id="pastConferences" role="tabpanel" aria-labelledby="home-tab">

                <ul class="list-group">
                    @foreach($pastRegistrations as $pastRegistration)
                        @foreach($pastRegistration->participants as $participant)
                            @if(!empty($pastRegistration->conference) || !empty($pastRegistration->conference->start_date))
                                <li class="list-group-item">
                                    <h5>{{optional($pastRegistration->conference)->name}}</h5>
                                    @if ($participant->registration_type->certificate_available == 'Y')
                                        <a href="{{route('conferences.certificateInfo',['regID'=> $pastRegistration->id])}}"
                                           class="btn btn-primary ml-2"><i
                                                    class="fa fa-file-pdf-o"></i> Download Certificate
                                        </a>
                                        @break
                                    @endif
                                    @if ($pastRegistration->status == 'C')
                                        <a href="{{route('conferences.registrationInfo',
                                    [
                                    'regID'=> $pastRegistration->id])}}"
                                           class="btn btn-primary ml-2"><i
                                                    class="fa fa-file-pdf-o"></i> Registration info
                                        </a>
                                    @endif
                                </li>
                            @endif
                        @endforeach
                    @endforeach
                </ul>
                <div class="text-center d-flex justify-content-center mt-3">
                    {{$pastRegistrations->fragment('pastConferences')->links("pagination::bootstrap-4")}}
                </div>
            </div>
        </div>
</div>
  • 写回答

1条回答 默认 最新

  • doudengjin8251 2018-07-24 20:14
    关注

    I assume session('searchedRegistrations') is the Pagination instance. There is no property named participants nor would there be any random properties (it is a container, not what it contains). I would imagine a model instance contained in the collection might have a participants property though.

    @foreach(session('searchedRegistrations') as $registration)
        @foreach(session('searchedRegistrations')->participants as $participant)
    

    I am guessing that should be

        @foreach($registration->participants as $participant)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c