Laravel 8 whereInstanceOf() {#collection-method}
2021-07-19 10:00 更新
whereInstanceOf
方法根据给定的类来过滤集合:
use App\Models\User;
use App\Models\Post;
$collection = collect([
new User,
new User,
new Post,
]);
$filtered = $collection->whereInstanceOf(User::class);
$filtered->all();
// [App\Models\User, App\Models\User]
以上内容是否对您有帮助:
更多建议: