PHPackages                             laravel-ready/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. laravel-ready/hasin

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

laravel-ready/hasin
===================

Laravel framework relation has in implement

v4.0.0(3mo ago)03.1k↓50%2MITPHPPHP ^8.5 || ^8.4 || ^8.3 || ^8.2 || ^8.1CI passing

Since Dec 21Pushed 3mo agoCompare

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

READMEChangelog (5)Dependencies (8)Versions (26)Used By (2)

Laravel hasIn
=============

[](#laravel-hasin)

[![Packagist Version](https://camo.githubusercontent.com/124521520d9a96e61a4594e523c3a575acb4bb0543788df9ec253b6684158748/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c2d72656164792f686173696e2e7376673f636f6c6f723d343039394445)](https://packagist.org/packages/laravel-ready/hasin)[![License](https://camo.githubusercontent.com/ffe7adf17b1d38c79e0e81f80884e0e21f43129b2b96c7a123ea3bd032f09cb2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d3733383944382e7376673f7374796c653d666c6174)](https://github.com/laravel-ready/hasin/blob/master/LICENSE)[![Release](https://camo.githubusercontent.com/6e7c89424698eb49d57e00986d928306a3027cbe5dae18b80ed4f29349871a9f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c61726176656c2d72656164792f686173696e2e7376673f636f6c6f723d343039394445)](https://github.com/laravel-ready/hasin/releases)[![Downloads](https://camo.githubusercontent.com/1231f9eb0475dc2715fd98df4844f1d6dd0979e65bf639db8642dbbc05c99fc2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c2d72656164792f686173696e2e7376673f636f6c6f723d)](https://packagist.org/packages/laravel-ready/hasin)[![PHP 8+](https://camo.githubusercontent.com/7ac021d087bea02c44fcb417d2c01f5f1b0ef7d8a57d8152e069177636309e3e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382b2d3539613966382e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/7ac021d087bea02c44fcb417d2c01f5f1b0ef7d8a57d8152e069177636309e3e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382b2d3539613966382e7376673f7374796c653d666c6174)

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 laravel-ready/hasin:^4.0`Laravel 11`composer require laravel-ready/hasin:^3.0`Laravel 10`composer require laravel-ready/hasin:^2.1`Laravel 9`composer require laravel-ready/hasin:^2.0`Laravel 5.5 ~ 8`composer require laravel-ready/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)`
>
> '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.

However, when the **User** 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
```

License
-------

[](#license)

[MIT](./LICENSE)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity19

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.7% 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 ~84 days

Recently: every ~260 days

Total

23

Last Release

119d ago

Major Versions

v0.5.0 → v1.0.02021-01-19

v1.4.2 → v2.0.02022-05-12

v2.1.4 → v3.0.02024-05-27

v3.0.0 → v4.0.02026-01-20

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

v0.5.0PHP &gt;=7.1

v4.0.0PHP ^8.5 || ^8.4 || ^8.3 || ^8.2 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8c5a4a2047094867ebe437462b827160e660b5e7bfbad68b57f8d255890d42a?d=identicon)[relliv](/maintainers/relliv)

---

Top Contributors

[![biiiiiigmonster](https://avatars.githubusercontent.com/u/42432833?v=4)](https://github.com/biiiiiigmonster "biiiiiigmonster (86 commits)")[![relliv](https://avatars.githubusercontent.com/u/17010054?v=4)](https://github.com/relliv "relliv (25 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (2 commits)")

---

Tags

laravelormrelationwhereHas

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[biiiiiigmonster/hasin

Laravel framework relation has in implement

154552.4k](/packages/biiiiiigmonster-hasin)[dcat/laravel-wherehasin

Laravel ORM whereHasIn

247149.8k4](/packages/dcat-laravel-wherehasin)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[laravel-doctrine/acl

ACL for Laravel and Doctrine

44445.3k7](/packages/laravel-doctrine-acl)

PHPackages © 2026

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