入力フォームを作成しています。
未入力や、数字でない場合にエラーの文字を出したいのですが、バリテーションが反映されていないです。
自分の見解として、ルーツの指定が間違っているような気がするのですがご教授お願いします。
php
1入力フォームになります。 2 3<div class="form-group"> 4 5 <label for="name">{{ __('名前') }}<span class="badge badge-danger ml-2">{{ __('必須') }}</span></label> 6 <input type="text" class="form-control" name="name" id="name" value="{{ old('name', $yubins->name) }}"> 7 @if($errors->has('name')) 8 {{ $errors->first('name') }}<br> 9 @endif 10 11 12 <label for="name">{{ __('郵便番号') }}<span class="badge badge-danger ml-2">{{ __('必須') }}</span></label> 13 <input type="text" class="form-control" name="post7" id="post7" value="{{ old('post7', $yubins->post7) }}"> 14 @if($errors->has('post7')) 15 @foreach($errors->get('post7') as $message) 16 {{ $message }}<br> 17 @endforeach 18 @endif
php
1コントローラーになります。 2ここで、editに表示したいバリテーションを書いています。 3 4 public function send(Request $request) 5 { 6 validate($request, [ 7 'name' => 'required', 8 'post7' => 'required', 9 ], [ 10 'name.required'=>':ご入力がまだです。', 11 'post7.required' => ':ご入力がまだです。', 12 ]); 13 return redirect('/create'); 14 } 15
php
1 2上記と同じファイルのコントローラーです。 3editは入力フォームのことです。 4 5 public function edit($id) 6 { 7 // 8 $yubins = Yubin::find($id); 9 10 11 return view('/edit',compact('yubins')); 12 } 13
php
1これが、web.phpになります。 2 3//バリテーション 4Route::post('/send', [App\Http\Controllers\YubinController::class, 'send'])->middleware('auth');
上記のもので足りなものがあれば、追記しますのでお申し付けください。
ララベルは9
データベースはmysql
クラウドナインで作成しております。
回答1件
あなたの回答
tips
プレビュー