LoginSignup
0
0

More than 3 years have passed since last update.

laravel初心者がバリデーションチェックでうっかりやらかしたこと〜その1

Last updated at Posted at 2020-03-28

今日はlaravel初心者(筆者)がやりがちなミスを書いていきたいと思います。

バリデーション処理をコントローラーに書いても何の反応も起きない→Viewに表示エラーを出すコードを書いていない

コントローラ側にバリデーション↓だけ書いてもバリデーションエラー表示はされません。

GroupController.php
//コントローラー側抜粋
    public function store(Request $request) {
        $validatedData = $request->validate([
            'title' => 'required|unique:groups,title|max:100',
            'description' => 'required|max:5000',
        ]);

↓をビュー側に書いて表示させましょう

index.html
<!-- index.blade.php の表示させたい側に-->
<small class="text-danger">{{ $errors->first('title') }}</small>
<small class="text-danger">{{ $errors->first('description') }}</small>

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