我有方法讓Word形式搜索欄和數據庫查詢,然後返回查看PHP Laravel返回查看空變量
但它顯示空表雖然我檢查空變量
這是控制器代碼
<?php
public function getSearch($title) {
$words = Word::where('title', $title)->first();
if (empty($words)) {
abort(404);
}
return view('dict.index', compact('words'));
}
這裏是視圖代碼
<?php
foreach ($words as $row) {
echo '<tr>';
echo '<td>' . $row['title'] . '</td>';
echo '<td>' . $row['meaning'] . '</td>';
echo '<td>';
for ($i = 0; $i < $row['rate']; $i++) {
echo '<img src="/images/pjdict/star.png" width="20" height="20">';
}
echo '</td>';
echo '</tr>';
}
我建議爲什麼我的觀點有空表,因爲 如果(空($字)){ \t \t \t中止(404); \t \t} 沒有輸入 –
我懷疑因爲我使用 - > first(); ?? –