【问题标题】:Why the published conferences dont appear?为什么已发布的会议不出现?
【发布时间】:2019-01-05 16:24:36
【问题描述】:

我有以下查询以获取已发布的会议:

$publishedConferences =
            $user->conferences()->
            where(function ($query) {
                $query->where('status', '=', 'P');
                $query->where('end_date','>', now());
            })
                ->paginate($pageLimit);

        dd($publishedConferences);

但 $publishedConferences 显示:

LengthAwarePaginator {#345 ▼
  #total: 1
  #lastPage: 1
  #items: Collection {#344 ▶}
  #perPage: 5
  #currentPage: 2
  #path: "https://proj.test/user/profile"
  #query: []
  #fragment: null
  #pageName: "page"
}

因此没有会​​议出现。但是在数据库中有一个状态等于“P”并且“end_date”是“now()”的会议。

你知道可能是什么问题吗?

显示已发布会议的 HTML:

<div class="tab-pane fade show clearfix" id="publishedConferences" role="tabpanel"
 aria-labelledby="home-tab">
    <ul class="list-group">
        @foreach($publishedConferences as $publishedConference)
            @if(!empty($publishedConference))
                <li class="list-group-item">
                    <p>{{$publishedConference->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                    <h5>{{$publishedConference->name}}</h5>
                </li>
            @endif
        @endforeach
    </ul>

    <div class="text-center d-flex justify-content-center mt-3">
        {{$publishedConferences->fragment('publishedConferences')->links("pagination::bootstrap-4")}}

    </div>
</div>

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    将where子句改为:

     // or toDateTimeString() if needed for datetime type column
     $query->where('end_date','>', now()->toDateString());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-01
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      相关资源
      最近更新 更多