阅读(3587)
赞(7)
Laravel 8 whereInstanceOf() {#collection-method}
2021-07-01 16:46:26 更新
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]