亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我無法檢查在具有count()集合的laravel 6中是否存在變量中的數據

我無法檢查在具有count()集合的laravel 6中是否存在變量中的數據

PHP
瀟湘沐 2022-08-19 10:04:29
我無法檢查 laravel 6 中的變量中是否有數據。這是函數。這里的問題是沒有命中其他語句$tags->count()public function index(){    $tags = Constant_model::getDataAllWithLimit('tags',"id",'DESC',50);    if ($tags->count() >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);    }}這里是getDataAllWithLimit函數public static function getDataAllWithLimit($table,$order_column,$order_type,$limit){    $data = DB::table("$table")->orderBy("$order_column", "$order_type")      ->paginate($limit);      return $data;  }
查看完整描述

2 回答

?
慕妹3242003

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);

}


查看完整回答
反對 回復 2022-08-19
?
幕布斯7119047

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);

}


查看完整回答
反對 回復 2022-08-19
  • 2 回答
  • 0 關注
  • 109 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號