3
4

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

laravelでClass 'App\Providers\Validator' not foundと出た場合の対処法

Last updated at Posted at 2018-07-06

エラー箇所を検討つける

laravelで

Class 'App\Providers\Validator' not found

というエラーが出た。

対処法ファイルはapp/Providers/ValidationServiceProvider.phpらしい
見てみると

13行目 return new Validator($translator, $data, $rules, $messages, $customAttributes);

のValidatorが適切に読み込まれていないらしい。
たぶんnamespaceが正しく読み込まれていないということだろう。

とりあえずconfig/app.phpを確認

基本的なエイリアスの定義はここにあるので、まずはconfig/app.phpの中からValidatorを探す。

すると、239行目に

'Validator' => Illuminate\Support\Facades\Validator::class,

とある。

とりあえずapp/Providers/ValidationServiceProvider.phpuse Validatorと入れてみる。

すると、次は以下のエラーがでる、、、

Call to undefined method Illuminate\Support\Facades\Validator::setPresenceVerifier()

対象ファイルはvendor/laravel/framework/src/Illuminate/Validation/Factory.phpみたいなのでとりあえず開く。

どうやら、$validatorが読み込まれていないみたいなのが原因らしい。

再び原因を探る

エラーをみるとsetPresenceVerifier()が定義されていないと出るので、setPresenceVerifier()が定義されているファイルvendor/laravel/framework/src/Illuminate/Validation/Validator.phpを開く

すると、1054行目にpublic function setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)があった。

ここがピンポイントというよりはValidator.php内のclass Validation自体が上手く読み込まれていないらしい。
つまりはuse Illumintion\Validation\Validatorvendor/laravel/framework/src/Illuminate/Validation/Factory.phpに上手く読み込ませればいい。

ということで、
vendor/laravel/framework/src/Illuminate/Validation/Factory.phpuse Illumintion\Validation\Validatorを記述

駄目だ同様のエラーがでる、、、

もしやと思い、app/Providers/ValidationServiceProvider.phpuse Validatoruse Illuminate\Support\Facades\Validatorに書き換えてみる。

解決

useする箇所を間違えてたらしい。
しかし、Validatorクラス多すぎだよ、、、

参照

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?