5
3

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.

laravel ビューファイルが存在していることを確認する

Posted at

目的

  • ビューファイルが存在しているかどうかを判定する方法をメモ的にまとめる

方法

  • 下記のようにコントローラーなどに記載することで指定したビューファイルが存在しているか判定する事ができる。

    // ファイル上部のエイリアス作成の部分に下記を記載する
    use Illuminate\Support\Facades\View;
    
    $viewFlag = View::exists('ビューファイル名');
    
  • Viewファサードのexistsメソッドは引数として指定されたビューファイルが存在しているときにtrueを、存在していないときにfalseを返す。

  • 下記のように記載することでビューファイルの有無で処理を分ける事ができる。

    // ファイル上部のエイリアス作成の部分に下記を記載する
    use Illuminate\Support\Facades\View;
    
    if (View::exists('ビューファイル名')) {
        // ビューファイルが存在していた時の処理
    } else {
        // ビューファイルが存在していなかった時の処理
    };
    

参考文献

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?