Laravel - 检查变量是集合还是字符串

时间:2017-08-31 10:20:36

标签: php arrays laravel laravel-5 blade

我有一个变量可以返回一个带有数据数组的集合,但是如果它是空的,它只会将一个字符串赋给同一个变量。目前,我的视图有foreach期望变量为数组。在运行刀片foreach之前,有没有办法检查集合?

$twitterResults = Manual::where('account_id', Auth::user()->account)
            ->where('twitter_followers', '>=', 0)
            ->where('twitter_posts', '>=', 0)
            ->where('twitter_reach', '>=', 0)
            ->where('date_recorded', '>=', Carbon::today()->subMonths(6))
            ->select('twitter_followers', 'twitter_posts', 'twitter_reach', 'date_recorded')
            ->orderBy('date_recorded', 'ASC')
            ->get();

if ($twitterResults->isEmpty()){
    $twitterResults = "We don't have enough data, to display any results yet.";
} else {

}

0 个答案:

没有答案