0
1

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.

Storage::path() と storage_path の使い分け

Posted at

たまに混同してハマるので覚え書き。
書くまでもないことかもしれませんが。

storage_path()

ヘルパ関数。
storage配下のパスを返す。

Storage::path()

Storageクラスのメソッド。
挙動はconfig/filesystems.phpの設定に基づくが、インストール時点の設定ではstorage/app配下のパスを返す。

どう使い分ければいいか

Storageクラスのメソッドを使った処理をする過程で使うなら、Storage::path()が適切。

例えばこんな風に。
ただStorage::files()はがディレクトリを返さないようになっているので、あんまり意味はないが。

foreach (Storage::files('data_sources') as $_file) {
    if (is_file(Storage::path($_file))) {
        // ...
    }
}

storage_path()はapp以外のディレクトリにもアクセスするときに使う。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?