PHPackages                             kanagama/laravel-eloquent-method-expansion - 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. kanagama/laravel-eloquent-method-expansion

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

kanagama/laravel-eloquent-method-expansion
==========================================

Eloquent メソッド拡張

v1.3.0(3y ago)139[2 PRs](https://github.com/kanagama/laravel-eloquent-method-expansion/pulls)MITPHPPHP ^7.4 | ^8.0 | ^8.1 | ^8.2CI failing

Since Dec 3Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (41)Used By (0)

Eloquent Method Expansion
=========================

[](#eloquent-method-expansion)

[testbench公式ドキュメント](https://orchestraplatform.readme.io/docs/testbench)

機能概要
----

[](#機能概要)

php7.4 以上 Laraevel8.0 以上

Eloquent を拡張し、メソッドを追加します。

（※正確には**拡張しているのは QueryBuilder** なのですが、リポジトリ名を先に決めてしまっていたので…）

### packagist

[](#packagist)

使い方
---

[](#使い方)

composer でインストール

```
composer require kanagama/laravel-eloquent-method-expansion
```

インストール後、下記メソッドが使えるようになります。

拡張 where 句
----------

[](#拡張-where-句)

※ **\[columnName\]** にはテーブルのカラム名をアッパーキャメルで入力します。

### where\[columnName\]IsNull(), orWhere\[columnName\]IsNull()

[](#wherecolumnnameisnull-orwherecolumnnameisnull)

where\[columnName\]IsNull() メソッドは、columnName が NULL である条件を加えます。

```
$users = DB::table('users')
            ->whereNameIsNull()
            ->get();
# select * from users where name IS NULL;
```

### where\[columnName\]IsNotNull(), orWhere\[columnName\]IsNotNull()

[](#wherecolumnnameisnotnull-orwherecolumnnameisnotnull)

where\[columnName\]IsNull() メソッドは、columnName が NULL でない条件を加えます。

```
$users = DB::table('users')
            ->whereNameIsNotNull()
            ->get();
# select * from users where name IS NOT NULL;
```

### where\[columnName\]Eq(), orWhere\[columnName\]Eq()

[](#wherecolumnnameeq-orwherecolumnnameeq)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Eq() メソッドは、 パラメータの値が columnName の値と一致する条件を加えます。

```
$users = DB::table('users')
            ->whereTelEq('09099999999')
            ->get();
# select * from users where tel = '09099999999';
```

### where\[columnName\]NotEq(), orWhere\[columnName\]NotEq()

[](#wherecolumnnamenoteq-orwherecolumnnamenoteq)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]NotEq() メソッドは、 パラメータの値が columnName の値と一致しない条件を加えます。

```
$users = DB::table('users')
            ->whereTelNotEq('09099999999')
            ->get();
# select * from users where tel  '09099999999';
```

### where\[columnName\]Gt(), orWhere\[columnName\]Gt()

[](#wherecolumnnamegt-orwherecolumnnamegt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Gt() メソッドは、パラメータの値より大きい columnName の値となる条件を加えます。

```
$users = DB::table('users')
            ->whereCreatedAtGt('1980-05-21')
            ->get();
# select * from users where created_at > '1980-05-21';
```

### where\[columnName\]Gte(), orWhere\[columnName\]Gte()

[](#wherecolumnnamegte-orwherecolumnnamegte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Gte() メソッドは、パラメータの値以上の columnName の値となる条件を加えます。

```
$users = DB::table('users')
            ->whereCreatedAtGte('1980-05-21')
            ->get();
# select * from users where created_at >= '1980-05-21';
```

### where\[columnName\]Lt(), orWhere\[columnName\]Lt()

[](#wherecolumnnamelt-orwherecolumnnamelt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Lt() メソッドは、パラメータの値より小さい columnName の値となる条件を加えます。

```
$users = DB::table('users')
            ->whereModifiedAtLt('1980-05-21 00:00:00')
            ->get();
# select * from users where modified_at < '1980-05-21 00:00:00';
```

### where\[columnName\]Lte(), orWhere\[columnName\]Lte()

[](#wherecolumnnamelte-orwherecolumnnamelte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Lte() メソッドは、パラメータの値以下の columnName の値となる条件を加えます。

```
$users = DB::table('users')
            ->whereModifiedAtLte('1980-05-21 00:00:00')
            ->get();
# select * from users where modified_at whereUserStatusIdIn([
                '1','2','3',
            ])
            ->get();
# select * from users where user_status_id in (1, 2, 3);
```

### where\[columnName\]NotIn(), orWhere\[columnName\]NotIn()

[](#wherecolumnnamenotin-orwherecolumnnamenotin)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]NotIn() メソッドは、指定した配列内に columnName の値が含まれない条件を加えます。

```
$users = DB::table('users')
            ->whereUserStatusIdNotIn([
                '1','2','3',
            ])
            ->get();
# select * from users where user_status_id not in (1, 2, 3);
```

### where\[columnName\]Like(), orWhere\[columnName\]Like()

[](#wherecolumnnamelike-orwherecolumnnamelike)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Like メソッドは、columName の値の中にパラメータの値が部分一致する条件を加えます。

```
$users = DB::table('users')
            ->whereAddressLike('沖縄県')
            ->get();
# select * from users where address like '%沖縄県%';
```

### where\[columnName\]NotLike(), orWhere\[columnName\]NotLike()

[](#wherecolumnnamenotlike-orwherecolumnnamenotlike)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]NotLike() メソッドは、columName の値の中にパラメータの値が部分一致しない条件を加えます。

```
$users = DB::table('users')
            ->whereAddressNotLike('沖縄県')
            ->get();
# select * from users where address not like '%沖縄県%';
```

### where\[columnName\]LikePrefix(), orWhere\[columnName\]LikePrefix()

[](#wherecolumnnamelikeprefix-orwherecolumnnamelikeprefix)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]LikePrefix() メソッドは、columName の値の中にパラメータの値が前方一致する条件を加えます。

```
$users = DB::table('users')
            ->whereAddressLikePrefix('沖縄県')
            ->get();
# select * from users where address like '沖縄県%';
```

### where\[columnName\]NotLikePrefix(), orWhere\[columnName\]NotLikePrefix()

[](#wherecolumnnamenotlikeprefix-orwherecolumnnamenotlikeprefix)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]LikePrefix() メソッドは、columName の値の中にパラメータの値が前方一致しない条件を加えます。

```
$users = DB::table('users')
            ->whereAddressNotLikePrefix('沖縄県')
            ->get();
# select * from users where address not like '沖縄県%';
```

### where\[columnName\]LikeBackword(), orWhere\[columnName\]Backword()

[](#wherecolumnnamelikebackword-orwherecolumnnamebackword)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]LikePrefix() メソッドは、columName の値の中にパラメータの値が後方一致する条件を加えます。

```
$users = DB::table('users')
            ->whereAddressLikeBackword('沖縄県')
            ->get();
# select * from users where address like '%沖縄県';
```

### where\[columnName\]NotLikeBackword(), orWhere\[columnName\]NotBackword()

[](#wherecolumnnamenotlikebackword-orwherecolumnnamenotbackword)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]LikePrefix メソッドは、columName の値の中にパラメータの値が後方一致しない条件を加えます。

```
$users = DB::table('users')
            ->whereAddressNotLikeBackword('沖縄県')
            ->get();
# select * from users where address not like '%沖縄県';
```

### where\[columnName\]Date(), orWhere\[columnName\]Date()

[](#wherecolumnnamedate-orwherecolumnnamedate)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]Date() メソッドは、columName の値と日付を比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeDate('2022-12-02')
            ->get();
# select * from `products` where date(`rent_datetime`) = "2022-12-02"
```

### where\[columnName\]DateGt(), orWhere\[columnName\]DateGt()

[](#wherecolumnnamedategt-orwherecolumnnamedategt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DateGt メソッドは、columName の値と日付を &gt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeDateGt('2022-12-02')
            ->get();
# select * from `products` where date(`rent_datetime`) > "2022-12-12"
```

### where\[columnName\]DateGte(), orWhere\[columnName\]DateGte()

[](#wherecolumnnamedategte-orwherecolumnnamedategte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DateGte() メソッドは、columName の値と日付を &gt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeDateGte('2022-12-02')
            ->get();
# select * from `products` where date(`rent_datetime`) >= "2022-12-12"
```

### where\[columnName\]DateLt(), orWhere\[columnName\]DateLt()

[](#wherecolumnnamedatelt-orwherecolumnnamedatelt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DateLt() メソッドは、columName の値と日付を &lt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeDateLt('2022-12-02')
            ->get();
# select * from `products` where date(`rent_datetime`) < "2022-12-12"
```

### where\[columnName\]DateLte(), orWhere\[columnName\]DateLte()

[](#wherecolumnnamedatelte-orwherecolumnnamedatelte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DateLte() メソッドは、columName の値と日付を &lt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeDateLte('2022-12-02')
            ->get();
# select * from `products` where date(`rent_datetime`) whereRentDatetimeMonth('12')
            ->get();
# select * from `products` where month(`rent_datetime`) = "12"
```

### where\[columnName\]MonthGt(), orWhere\[columnName\]MonthGt()

[](#wherecolumnnamemonthgt-orwherecolumnnamemonthgt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]MonthGt() メソッドは、columName の値と特定の月を &gt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthGt('10')
            ->get();
# select * from `products` where month(`rent_datetime`) > "10"
```

### where\[columnName\]MonthGte(), orWhere\[columnName\]MonthGte()

[](#wherecolumnnamemonthgte-orwherecolumnnamemonthgte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]MonthGte() メソッドは、columName の値と特定の月を &gt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthGte('10')
            ->get();
# select * from `products` where month(`rent_datetime`) >= "10"
```

### where\[columnName\]MonthLt(), orWhere\[columnName\]MonthLt()

[](#wherecolumnnamemonthlt-orwherecolumnnamemonthlt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]MonthLt() メソッドは、columName の値と特定の月を &lt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthLt('10')
            ->get();
# select * from `products` where month(`rent_datetime`) < "10"
```

### where\[columnName\]MonthLte(), orWhere\[columnName\]MonthLte()

[](#wherecolumnnamemonthlte-orwherecolumnnamemonthlte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]MonthLte() メソッドは、columName の値と特定の月を &lt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthLte('10')
            ->get();
# select * from `products` where month(`rent_datetime`) whereRentDatetimeMonth('31')
            ->get();
# select * from `products` where day(`rent_datetime`) = "31"
```

### where\[columnName\]DayGt(), orWhere\[columnName\]DayGt()

[](#wherecolumnnamedaygt-orwherecolumnnamedaygt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DayGt() メソッドは、columName の値と特定の日を &gt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthGt('15')
            ->get();
# select * from `products` where day(`rent_datetime`) > "15"
```

### where\[columnName\]DayGte(), orWhere\[columnName\]DayGte()

[](#wherecolumnnamedaygte-orwherecolumnnamedaygte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DayGte() メソッドは、columName の値と特定の日を &gt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthGte('15')
            ->get();
# select * from `products` where day(`rent_datetime`) >= "15"
```

### where\[columnName\]DayLt(), orWhere\[columnName\]DayLt()

[](#wherecolumnnamedaylt-orwherecolumnnamedaylt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DayLt() メソッドは、columName の値と特定の日を &lt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthLt('15')
            ->get();
# select * from `products` where day(`rent_datetime`) < "15"
```

### where\[columnName\]DayLte(), orWhere\[columnName\]DayLte()

[](#wherecolumnnamedaylte-orwherecolumnnamedaylte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]DayLte() メソッドは、columName の値と特定の日を &lt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeMonthLte('15')
            ->get();
# select * from `products` where day(`rent_datetime`) whereRentDatetimeYear('2022')
            ->get();
# select * from `products` where year(`rent_datetime`) = "2022"
```

### where\[columnName\]YearGt(), orWhere\[columnName\]YearGt()

[](#wherecolumnnameyeargt-orwherecolumnnameyeargt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]YearGt() メソッドは、columName の値と特定の年を &gt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeYearGt('2022')
            ->get();
# select * from `products` where year(`rent_datetime`) > "2022"
```

### where\[columnName\]YearGte(), orWhere\[columnName\]YearGte()

[](#wherecolumnnameyeargte-orwherecolumnnameyeargte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]YearGte() メソッドは、columName の値と特定の年を &gt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeYearGte('2022')
            ->get();
# select * from `products` where year(`rent_datetime`) >= "2022"
```

### where\[columnName\]YearLt(), orWhere\[columnName\]YearLt()

[](#wherecolumnnameyearlt-orwherecolumnnameyearlt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]YearLt() メソッドは、columName の値と特定の年を &lt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeYearLt('2022')
            ->get();
# select * from `products` where year(`rent_datetime`) < "2022"
```

### where\[columnName\]YearLte(), orWhere\[columnName\]YearLte()

[](#wherecolumnnameyearlte-orwherecolumnnameyearlte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]YearLte() メソッドは、columName の値と特定の年を &lt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeYearLte('2022')
            ->get();
# select * from `products` where year(`rent_datetime`) whereRentDatetimeTime('12:00:00')
            ->get();
# select * from `products` where time(`rent_datetime`) = "12:00:00"
```

### where\[columnName\]TimeGt(), orWhere\[columnName\]TimeGt()

[](#wherecolumnnametimegt-orwherecolumnnametimegt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]TimeGt() メソッドは、columName の値と特定の時間を &gt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeTimeGt('12:00:00')
            ->get();
# select * from `products` where time(`rent_datetime`) > "12:00:00"
```

### where\[columnName\]TimeGte(), orWhere\[columnName\]TimeGte()

[](#wherecolumnnametimegte-orwherecolumnnametimegte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]TimeGte() メソッドは、columName の値と特定の時間を &gt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeTimeGte('12:00:00')
            ->get();
# select * from `products` where time(`rent_datetime`) >= "12:00:00"
```

### where\[columnName\]TimeLt(), orWhere\[columnName\]TimeLt()

[](#wherecolumnnametimelt-orwherecolumnnametimelt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]TimeLt() メソッドは、columName の値と特定の時間を &lt; で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeTimeLt('12:00:00')
            ->get();
# select * from `products` where time(`rent_datetime`) < "12:00:00"
```

### where\[columnName\]TimeLte(), orWhere\[columnName\]TimeLte()

[](#wherecolumnnametimelte-orwherecolumnnametimelte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]TimeLte() メソッドは、columName の値と特定の時間を &lt;= で比較します。

```
$users = DB::table('users')
            ->whereRentDatetimeTimeLte('12:00:00')
            ->get();
# select * from `products` where time(`rent_datetime`) whereRentDateColumn('return_date')
            ->get();
# select * from `products` where `rent_date` = `return_date`
```

### where\[columnName\]ColumnGt(), orWhere\[columnName\]ColumnGt()

[](#wherecolumnnamecolumngt-orwherecolumnnamecolumngt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]ColumnGt() メソッドは、columnName が指定したカラムの値より大きい条件を加えます。

```
$users = DB::table('users')
            ->whereRentDateColumnGt('return_date')
            ->get();
# select * from `products` where `rent_date` > `return_date`
```

### where\[columnName\]ColumnGte(), orWhere\[columnName\]ColumnGte()

[](#wherecolumnnamecolumngte-orwherecolumnnamecolumngte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]ColumnGt() メソッドは、columnName が指定したカラムの値以上となる条件を加えます。

```
$users = DB::table('users')
            ->whereRentDateColumnGte('return_date')
            ->get();
# select * from `products` where `rent_date` >= `return_date`
```

### where\[columnName\]ColumnLt(), orWhere\[columnName\]ColumnLt()

[](#wherecolumnnamecolumnlt-orwherecolumnnamecolumnlt)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]ColumnLt() メソッドは、columnName が指定したカラムの値より小さい条件を加えます。

```
$users = DB::table('users')
            ->whereRentDateColumnLt('return_date')
            ->get();
# select * from `products` where `rent_date` < `return_date`
```

### where\[columnName\]ColumnLte(), orWhere\[columnName\]ColumnLte()

[](#wherecolumnnamecolumnlte-orwherecolumnnamecolumnlte)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]ColumnLte() メソッドは、columnName が指定したカラムの値以下となる条件を加えます。

```
$users = DB::table('users')
            ->whereRentDateColumnLt('return_date')
            ->get();
# select * from `products` where `rent_date` whereCreatedAtBetween(['2022-12-01', '2022-12-10',])
            ->get();
# select * from users where created_at between '2022-12-01' AND '2022-12-10'
```

### where\[columnName\]NotBetween(), orWhere\[columnName\]NotBetween()

[](#wherecolumnnamenotbetween-orwherecolumnnamenotbetween)

※ [AllowEmpty](#allowempty) オプション対応

where\[columnName\]NotBetween() メソッドは、columnName の値が２つの値の間にない条件を加えます

```
$users = DB::table('users')
            ->whereCreatedAtNotBetween(['2022-12-01', '2022-12-10',])
            ->get();
# select * from users where created_at not between '2022-12-01' AND '2022-12-10'
```

allowEmpty
----------

[](#allowempty)

**allowEmpty**オプション

where の後に **AllowEmpty** オプションを付与すると、パラメータが null や \[\] や 文字列の '' となる場合にその条件を省略します。

```
# $rentDatetime = null;
# $returnDatetime = '1980-05-21 00:00:00'
$users = DB::table('users')
            ->whereAllowEmptyRentDatetimeGte($rentDatetime)
            ->whereAllowEmptyReturnDatetimeGte($returnDatetime)
            ->get();
# null のため、whereAllowEmptyRentDatetimeGte() は省略される
# select * from users where return_datetime >= '1980-05-21 00:00:00';
```

AllowEmpty チェックしている条件は下記の通りです

```
# 渡されたパラメータがこの条件を満たさない場合、その条件は省略されます
# int の 0 と string の '0" は省略させたくなかったので、この条件にしています
if (!empty($parameters) || is_numeric($parameter)) {
```

### allowEmpty の使い所

[](#allowempty-の使い所)

管理画面（※予約管理画面など）では、予約者名、予約日、メールアドレス、電話番号、予約ステータス、その他多岐にわたる絞り込み条件が用意されていると思いますが、それを空かどうかチェックして空でなければ絞り込み条件に追加、というのを Eloquent で書くのは意外と労力が掛かります。

```
$query = DB::table('reservations');

# 絞り込み条件がリクエストパラメータに存在しているかチェックして where に追加しないといけない
if ($request->reserve_name) {
    $query->where('reservations.name', 'LIKE', '%'. $request->reserve_name . '%');
}
if ($request->reserve_date) {
    $query->whereDate('reservations.reserve_date_at', $request->reserve_date);
}
if ($request->email) {
    $query->whereEmail($request->email);
}
if ($request->tel) {
    $query->whereTel($request->tel);
}
if ($request->status) {
    $query->whereStatus($request->status);
}
// 絞り込み条件の数だけ続く
```

全部 if 文で囲むとかそんなんやってらんないよ、と思った際に使うのが **AllowEmpty** オプションです。

null や \[\] が渡された場合、その絞り込み条件を省略しますので、メソッドチェーンで全て繋げることが可能です。

```
return DB::table('reservations')
    ->whereAllowEmptyNameLike($request->reserve_name)
    ->whereAllowEmptyReserveDateAtDate($request->reserve_date)
    ->whereAllowEmptyEmailEq($request->email)
    ->whereAllowEmptyTelEq($request->tel)
    ->whereAllowEmptyStatusEq($request->status)
    ->get();
```

### AllowEmpty オプション利用不可

[](#allowempty-オプション利用不可)

- where\[columnName\]IsNull()
- orWhere\[columnName\]IsNull()
- where\[columnName\]Null()
- orWhere\[columnName\]Null()
- where\[columnName\]NotNull()
- orWhere\[columnName\]NotNull()
- where\[columnName\]IsNotNull()
- orWhere\[columnName\]IsNotNull()

拡張 orderBy 句
------------

[](#拡張-orderby-句)

### orderBy\[columnName\]Asc()

[](#orderbycolumnnameasc)

orderBy\[columnName\]Asc() メソッドは、columnName の昇順で並び替えます。

```
$users = DB::table('users')
            ->orderByCreatedAtAsc()
            ->get();
# select * from users order by created_at asc
```

### orderBy\[columName\]Desc()

[](#orderbycolumnamedesc)

orderBy\[columnName\]Desc() メソッドは、columnName の降順で並び替えます。

```
$users = DB::table('users')
            ->orderByCreatedAtDesc()
            ->get();
# select * from users order by created_at desc
```

### orderBy\[columnName\]Field()

[](#orderbycolumnnamefield)

orderBy\[columnName\]Field() メソッドは、columnName の指定した順番で並び替えます。 **null を末尾に配置するため、Desc が付与されます**

```
$users = DB::table('users')
            ->orderByIdField([2, 1, 4, 3,])
            ->get();
# select * from users order by FIELD(id, 3, 4, 1, 2) DESC;
```

開発コンテナ
======

[](#開発コンテナ)

```
make deelopment-build
make development
```

PHPUnit コンテナ
============

[](#phpunit-コンテナ)

PHP7.4 PHP8.0 PHP8.1 PHP8.2
---------------------------

[](#php74-php80-php81-php82)

```
make test-build
make test
```

※コンテナ起動時にテストが実行される

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 95.6% 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 ~3 days

Recently: every ~25 days

Total

36

Last Release

1153d ago

Major Versions

v0.9.2.x-dev → v1.0.02022-12-04

PHP version history (2 changes)v0.0.1PHP ^8.0

v1.3.0PHP ^7.4 | ^8.0 | ^8.1 | ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/be317eed08600136c2e3350d92d57160b0a683957131591389d9bd42fa3b543e?d=identicon)[k-nagama](/maintainers/k-nagama)

---

Top Contributors

[![kanagama](https://avatars.githubusercontent.com/u/80406579?v=4)](https://github.com/kanagama "kanagama (65 commits)")[![kazumacchi](https://avatars.githubusercontent.com/u/46663366?v=4)](https://github.com/kazumacchi "kazumacchi (3 commits)")

---

Tags

laraveleloquentformrequest

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kanagama-laravel-eloquent-method-expansion/health.svg)

```
[![Health](https://phpackages.com/badges/kanagama-laravel-eloquent-method-expansion/health.svg)](https://phpackages.com/packages/kanagama-laravel-eloquent-method-expansion)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)

PHPackages © 2026

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