PHPackages                             biiiiiigmonster/hasin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. biiiiiigmonster/hasin

ActiveLibrary[Database &amp; ORM](/categories/database)

biiiiiigmonster/hasin
=====================

Laravel framework relation has in implement

v5.1.0(2mo ago)154552.4k—3.8%17[2 PRs](https://github.com/biiiiiigmonster/hasin/pulls)MITPHPCI passing

Since Dec 21Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/biiiiiigmonster/hasin)[ Packagist](https://packagist.org/packages/biiiiiigmonster/hasin)[ RSS](/packages/biiiiiigmonster-hasin/feed)WikiDiscussions laravel-v12 Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (38)Used By (0)

English | [中文](./README-CN.md)

LARAVEL HASIN
=============

[](#laravel-hasin)

[![Latest Version on Packagist](https://camo.githubusercontent.com/33e3b2268fba07f8d961082405007ddb52c131a7d0da71d792ee585884faaf31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62696969696969676d6f6e737465722f686173696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/biiiiiigmonster/hasin)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9e546c6e2ed885e2279b4972019615e994b5982c689d367823ba50d2012eecf8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62696969696969676d6f6e737465722f686173696e2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/biiiiiigmonster/hasin/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d37b147392db7266e56718e96ea181579d1d9c1540ca3d6d49e0df0c45c9292f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62696969696969676d6f6e737465722f686173696e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/biiiiiigmonster/hasin/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/baa3c69dd83bfc59b6a5acf7916576bd755955a9cc19ca65f3b8afd8572b6503/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62696969696969676d6f6e737465722f686173696e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/biiiiiigmonster/hasin?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/81e8abe5cc4156bb33ac2b6e23db26dee46aa60f30c7a648ff06cdec66859fdf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62696969696969676d6f6e737465722f686173696e2e7376673f6c6162656c3d5363727574696e697a6572267374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/biiiiiigmonster/hasin/)[![Total Downloads](https://camo.githubusercontent.com/715b2b578960b220159c46ab47bd7e903256b4eab0ae8818646809f4faa184d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62696969696969676d6f6e737465722f686173696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/biiiiiigmonster/hasin)

The `hasin` is composer package based on `where in` syntax to query the relationship of `laravel ORM`, which can replace `has` based on `where exists` syntax in some business scenarios to obtain higher performance.

Installation
============

[](#installation)

Laravel VersionInstall commandLaravel 12`composer require biiiiiigmonster/hasin:^5.0`Laravel 11`composer require biiiiiigmonster/hasin:^4.0`Laravel 10`composer require biiiiiigmonster/hasin:^3.0`Laravel 9`composer require biiiiiigmonster/hasin:^2.0`Laravel 5.5 ~ 8`composer require biiiiiigmonster/hasin:^1.0`Introductions
=============

[](#introductions)

The relationship of `laravel ORM` is very powerful, and the query `has` based on the relationship also provides us with many flexible calling methods. However, in some cases, `has` is implemented with **where exists** syntax.

For example:

```
// User hasMany Post
User::has('posts')->get();
```

#### `select * from users where exists (select * from posts where users.id = posts.user_id)`

[](#select--from-users-where-exists-select--from-posts-where-usersid--postsuser_id)

> 'exists' is a loop to the external table, and then queries the internal table (subQuery) every time. Because the index used for the query of the internal table (the internal table is efficient, so it can be used as a large table), and how much of the external table needs to be traversed, it is inevitable (try to use a small table), so the use of exists for the large internal table can speed up the efficiency.

When the **User** table has a large amount of data, there will be performance problems, so the **where in** syntax will greatly improve the performance.

#### `select * from users where users.id in (select posts.user_id from posts)`

[](#select--from-users-where-usersid-in-select-postsuser_id-from-posts)

> 'in' is to hash connect the appearance and inner table, first query the inner table, then match the result of the inner table with the appearance, and use the index for the outer table (the appearance is efficient, and large tables can be used). Most of the inner tables need to be queried, which is inevitable. Therefore, using 'in' with large appearance can speed up the efficiency.

Therefore, the use of `has(hasMorph)` or `hasIn(hasMorphIn)` in code should be determined by **data size**

```
/**
 * SQL:
 *
 * select * from `users`
 * where exists
 *   (
 *      select * from `posts`
 *      where `users`.`id` = `posts`.`user_id`
 *   )
 * limit 10 offset 0
 */
$users = User::has('posts')->paginate(10);

/**
 * SQL:
 *
 * select * from `users`
 * where `users`.`id` in
 *   (
 *      select `posts`.`user_id` from `posts`
 *   )
 * limit 10 offset 0
 */
$users = User::hasIn('posts')->paginate(10);
```

Usage example
=============

[](#usage-example)

`hasIn(hasMorphIn)` supports all `Relations` in `laravel ORM`. The call mode and internal implementation are completely consistent with `has(hasMorph)` of the framework.

> hasIn

```
// hasIn
User::hasIn('posts')->get();

// orHasIn
User::where('age', '>', 18)->orHasIn('posts')->get();

// doesntHaveIn
User::doesntHaveIn('posts')->get();

// orDoesntHaveIn
User::where('age', '>', 18)->orDoesntHaveIn('posts')->get();
```

> whereHasIn

```
// whereHasIn
User::whereHasIn('posts', function ($query) {
    $query->where('votes', '>', 10);
})->get();

// orWhereHasIn
User::where('age', '>', 18)->orWhereHasIn('posts', function ($query) {
    $query->where('votes', '>', 10);
})->get();

// whereDoesntHaveIn
User::whereDoesntHaveIn('posts', function ($query) {
    $query->where('votes', '>', 10);
})->get();

// orWhereDoesntHaveIn
User::where('age', '>', 18)->orWhereDoesntHaveIn('posts', function ($query) {
    $query->where('votes', '>', 10);
})->get();
```

> hasMorphIn

```
Image::hasMorphIn('imageable', [Post::class, Comment::class])->get();
```

### Nested Relation

[](#nested-relation)

```
User::hasIn('posts.comments')->get();
```

Testing
=======

[](#testing)

```
composer test
```

> **Tips**: before testing, you need to configure your database connection in the `phpunit.xml.dist`.

License
=======

[](#license)

[MIT](./LICENSE)

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance84

Actively maintained with recent releases

Popularity54

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 72.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~182 days

Total

28

Last Release

61d ago

Major Versions

v0.5.0 → v1.0.02021-01-19

v1.4.2 → v2.0.02022-05-12

v2.2.0 → v3.0.02023-05-15

v3.1.0 → v4.0.02024-03-17

v4.0.1 → v5.0.02025-03-04

PHP version history (2 changes)v0.1.1PHP &gt;=7

v0.5.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9418a5a0d5e68adddc935dcf54fdddce95b04bb1edc5b435d6f144927f76172f?d=identicon)[biiiiiigmonster](/maintainers/biiiiiigmonster)

---

Top Contributors

[![biiiiiigmonster](https://avatars.githubusercontent.com/u/42432833?v=4)](https://github.com/biiiiiigmonster "biiiiiigmonster (122 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (24 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")[![27pchrisl](https://avatars.githubusercontent.com/u/6286310?v=4)](https://github.com/27pchrisl "27pchrisl (3 commits)")[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![AlexGodbehere](https://avatars.githubusercontent.com/u/114239316?v=4)](https://github.com/AlexGodbehere "AlexGodbehere (1 commits)")

---

Tags

hasinlaravelphplaravelormrelationwhereHas

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/biiiiiigmonster-hasin/health.svg)

```
[![Health](https://phpackages.com/badges/biiiiiigmonster-hasin/health.svg)](https://phpackages.com/packages/biiiiiigmonster-hasin)
```

###  Alternatives

[dcat/laravel-wherehasin

Laravel ORM whereHasIn

247149.8k4](/packages/dcat-laravel-wherehasin)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

101.6k](/packages/ramadan-easy-model)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
