Laravel 检查集合是否为空
本文介绍了Laravel 检查集合是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 Laravel 网络应用中有这个:
I've got this in my Laravel webapp:
我如何检查是否有任何$mentors->intern->employee
?
How could I check if there are any $mentors->intern->employee
?
当我这样做时:
它不会检查那个.
推荐答案
您可以随时统计集合.例如 $mentor->intern->count()
将返回导师有多少实习生.
You can always count the collection. For example $mentor->intern->count()
will return how many intern does a mentor have.
https://laravel.com/docs/5.2/collections#method-count
在你的代码中你可以做这样的事情
In your code you can do something like this
这篇关于Laravel 检查集合是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!