0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Laravel】特定のレコードを先頭に並べる方法!

Posted at

こんにちは、泉(@izumin_0401)です。

今回は、Laravelで特定のレコードを先頭に並べる方法を解説するよ!

ブログ記事はこちら

Laravelで特定のレコードを先頭に並べる方法

例えば、ユーザマスタがあって、IDが「0003」のレコードを先頭にしたい場合は以下。

$users = DB::table('mst_user')
          ->orderByRaw('id')
          ->get();

return $users->partition(function ($user) {
  return $user->id === '0003';
})->flatten();

超スマート!!

まとめ

ChatGPTに聞いたのは内緒だよ。

最後に

暇つぶしにTwitterブログもやってるので見てね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?