2 回答

TA貢獻1824條經驗 獲得超6個贊
你可以使用PHP的count()來計算所有元素。
public function index()
{
$tags = Constant_model::getDataAllWithLimit('tags', 'id', 'DESC', 50);
if (count($tags) > 0) {
$data = array(
'title' => 'All Tags',
'description' => 'All Tags',
'seo_keywords' => 'All Tags',
'tags' => $tags
);
return view('tags', $data);
}
$data = array(
'title' => 'Page Not found',
'description' => 'Page not found',
'seo_keywords' => '',
);
return view('404', $data);
}
public function getDataAllWithLimit($table, $order_column, $order_type, $limit)
{
return DB::table($table)->orderBy($order_column, $order_type)->paginate($limit);
}

TA貢獻1794條經驗 獲得超8個贊
試試這個,希望它有幫助...
if (count($tags->toArray()['data']) > 0) {
$data = array(
'title'=>'All Tags',
'description'=>'All Tags',
'seo_keywords'=>'All Tags',
'tags'=>$tags
);
return view('tags',$data);
}else{
$data = array(
'title'=>"Page Not found",
'description'=>"Page not found",
'seo_keywords'=>'',
);
return view('404',$data);
}
- 2 回答
- 0 關注
- 109 瀏覽
添加回答
舉報