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

【laravel 8】 undifined type 'Validator' エラー解消

Last updated at Posted at 2021-05-27

はじめに

laravel8で投稿機能のコントローラを実装していたときに出たundefined type 'Validator'エラーの解決方法についての記事です。

環境

PHP 8.0.6
laravel 8.42.1

エラー内容

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Post;
use Validator;    // ここ

class PostController extends Controller
{
    public function store(Request $request)
    {
          (省略)

        $validator = Validator::make($form, $rules, $message);

          (省略)

    }
}

↑のuse Validatorのところをネットの記事を参考に色々と変えてみても↓のようにValidatorが未定義と言われてしまいました。

undefined_validator.png

解消方法

色々な記事を漁ってもうまく行かず、最終的に公式ドキュメントで調べてみたら

use Illuminate\Support\Facades\Validator;

laravel8では↑を使うようでした。。。

まとめ

新しいバージョンこそ公式ドキュメント大事。。。

3
0
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
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?