1
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?

More than 1 year has passed since last update.

Laravel とPHP TipsAdvent Calendar 2023

Day 1

Collectionに対する繰り返し処理にはeachを使おう

Posted at

概要

Collectionを用いた処理を書く際に全てforeachで書いてませんか?
eachメソッドを使うと、引数に型宣言を行えるのでエディタの補完も効きやすくなります。

Illuminate\Database\Eloquent\Collectionでも、
Illuminate\Support\Collectionの両方で使えます。

私はPhpStormを使用しています。PhpStorm使おう

foreachの場合

スクリーンショット 2023-12-06 9.47.05.png

eachメソッドの場合

スクリーンショット 2023-12-06 9.46.18.png

参考

1
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
1
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?