【发布时间】:2019-05-21 16:18:35
【问题描述】:
发生了一件非常奇怪的事情。所以我有一个名为 Lactinfo_News 的表,有 1 行。我还创建了一个名为 LACTINFO_VW_LatestNews 的视图,其中包含“SELECT * FROM Lactinfo_News”并返回相同的 1 行。
我正在使用 Eloquent,并且在我的新闻管理器中,
public function GetLatestNews($rowsPerPage) {
$list = DB::table('LACTINFO_VW_LatestNews')
->orderBy('RegistedDate', 'DESC')
->paginate($rowsPerPage);
return $list;
}
where $rowsPerPage = 30.
在我的控制器中,
// >> current page
$page = '1';
if (! empty ( $request->query ( 'page' ) )) {
$page = $request->query ( 'page' );
}
// >> search
$nM = new NewsManager();
$list = $nM->GetLatestNews($page, $this->nbOfRowsPage);
return view ('admin.news.index', [
'results' => compact($list),
'page' => $page,
'startDate' => $startDate,
'endDate'=>$endDate
] );
}
在我看来,
<table id="news-results" class="hover responsive" style="margin-top: 20px;">
<thead>
<tr>
<th scope="column">Título</th>
<th scope="column">Descrição</th>
<th scope="column">Data Início</th>
<th scope="column">Ficheiro</th>
<th scope="column">Registada em</th>
<th scope="column">Criada por</th>
</tr>
</thead>
<tbody>
@if (count($results) > 0)
@foreach ($results as $r)
<tr>
<td>{{ $r->title }}</td>
<td>{{ $r->description }}</td>
<td>{{ Carbon\Carbon::parse($r->startDate)->format('d/m/Y') }}</td>
<td>{{ $r->fileURL }}</td>
<td>{{ $r->registedDate }}</td>
<td>{{ $r->createdBy }}</td>
</tr>
@endforeach
@else
<tr><td colspan="11">Não existem notícias criadas</td></tr>
@endif
</tbody>
</table>
如果我转储 $results 变量为空..
发生了什么事?这真的很奇怪:S 我认为我不需要执行任何工匠命令,因为我已经向我的经理添加了一个新功能,但我被这个问题困扰了几天......
【问题讨论】:
-
尝试
compact('list')而不是compact($list) -
没什么,我已经完成了 {{dd($results)}} 并且在我的数组列表中,查询键有 []...
-
如果您在控制器中
dd($list);在此行$list = $nM->GetLatestNews($page, $this->nbOfRowsPage);之后。 $list 变量中有一些数据吗? -
是这样!!非常感谢大佬!!我会更新我的答案!
标签: php laravel laravel-5 eloquent