2
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 1 year has passed since last update.

【Laravel7】Class view does not exist

Last updated at Posted at 2020-04-12

環境

  • PHP 7.4.4
  • Laravel 7.5.1

エラー

NOTICE: PHP message: PHP Fatal error:  Uncaught ReflectionException: Class view does not exist in /work/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php:805
Stack trace:
#0 /work/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(805): ReflectionClass->__construct('view')
#1 /work/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(687): Illuminate\Container\Container->build('view')
#2 /work/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(794): Illuminate\Container\Container->resolve('view', Array, true)
#3 /work/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Foundation\Application->resolve('view', Array)
#4 /work/backend/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(779): Illuminate\Container\Container->make('view', Array)
#5 /work/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php(1247): Illuminate\Foundation\Application->make('view')
#6 /work/backend/vendor/laravel/framewo in /work/backend/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 807

エラーメッセージが不親切で、 view がどうの言ってますがまったく関係ありません。
実際のエラーをデバッグする際はLaravelの例外ハンドラにデバッグコードを追記して処理を追うと良いです。

app/Exceptions/Handler.php
    public function render($request, Throwable $e)
    {
        dd($e);
        return parent::render($request, $e);
    }

原因

  • git clone した後に .env の作成を忘れていた。
  • .env の所有者が root ユーザーになっていてHttpアクセス経由から参照できなかった。

対策

$ cp .env.example .env
$ php artisan key:generate
2
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
2
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?