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 3 years have passed since last update.

Laravel6 Storageファサードでエラーが出た

Posted at

目的

  • Storageファサードを使ってファイルの存在を確認しようとしたときに出たエラーを紹介する

原因

  • 今回のエラーの原因は単純で筆者がtypoしていただけだった。

実施環境

  • ハードウェア環境
項目 情報
OS macOS Catalina(10.15.5)
ハードウェア MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
プロセッサ 2 GHz クアッドコアIntel Core i5
メモリ 32 GB 3733 MHz LPDDR4
グラフィックス Intel Iris Plus Graphics 1536 MB
  • ソフトウェア環境
項目 情報 備考
PHP バージョン 7.4.8 Homebrewを用いてこちらの方法で導入→Mac HomebrewでPHPをインストールする
Laravel バージョン 6.X commposerを用いてこちらの方法で導入→Mac Laravelの環境構築を行う
MySQLバージョン 8.0.19 for osx10.13 on x86_64 Homwbrewを用いてこちらの方法で導入→Mac HomebrewでMySQLをインストールする

問題までの経緯

  • Storageファサードとファイルパスを使用してファイルの存在を確認する三項演算子を書いていた。

  • ファイルパス先にファイルの存在を確認し真の場合ファイルをダウンロード、偽の場合エラーページにリダイレクトする処理である。

    return Storage::exsits(ファイルパス) ? Storage::download(ファイルパス) : redirect(route('error'));
    

問題

  • ファイルが存在しているにも関わらずファイルをダウンロードする事ができない。

  • というよりエラーページにリダイレクトされているわけでも無いのでファイルの存在を確認している部分がおかしい。

  • エラー内容を下記に記載する。

    BadMethodCallException
    Call to undefined method League\Flysystem\Filesystem::exsits
    

問題解決までの経緯

  • Storageファサードがuseされているかの確認やファイルパスがnullになってないかなどを確認したが問題はなかった。
  • お気づきだとは思うがStorageファサードのメソッド指定部分でtypoしている。
  • exsitsではなくexistsが正しい。
  • typoしていた部分を正常に記載したところ問題なく処理が実行された。
1
0
1

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?